Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a oAuth request using java?
    primarykey
    data
    text
    <p>I need to make a connection with <a href="http://developer.viagogo.net/documentation/api-security/oauth-authentication-for-public-services">Viagogo website</a> using oAuth. Referring to their <a href="http://developer.viagogo.net/documentation/api-security/oauth-authentication-for-public-services">documentation</a> I need to create a request similar to the following one </p> <pre><code>Using the example in step 1A, this means you may generate a signature base string that looks like the following: GET&amp;http%3A%2F%2Fapi.viagogo.net%2FPublic%2FSimpleOAuthAccessRequest&amp;oauth_consumer_key%3Dtestkey%26oauth_nonce%3Dmyn0nc3%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1292404912%26oauth_version%3D1.0%26scope%3DAPI.Public </code></pre> <p>I am using the following code but when I comment lines 1,2 it return <em>unauthorized error</em>, and when I use them it shows <em>oauthService.signRequest</em> returns void.</p> <p>TradeKingAPI.java</p> <pre><code>import org.scribe.builder.api.DefaultApi10a; import org.scribe.model.Token; public class TradeKingAPI extends DefaultApi10a { @Override public String getRequestTokenEndpoint() { return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest"; } @Override public String getAccessTokenEndpoint() { return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest"; } @Override public String getAuthorizationUrl(Token requestToken) { return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest"; } } </code></pre> <p>main.java</p> <pre><code>import org.scribe.builder.ServiceBuilder; import org.scribe.model.OAuthRequest; import org.scribe.model.Response; import org.scribe.model.Token; import org.scribe.model.Verb; import org.scribe.oauth.OAuthService; import api.TradeKingAPI; import org.scribe.builder.api.DefaultApi10a; import org.scribe.model.OAuthConstants; import org.scribe.oauth.OAuthService; ........ OAuthService oauthService = new ServiceBuilder() .provider(TradeKingAPI.class) .apiKey("My consumer key") .apiSecret("My secret") .scope("API.Public") .build(); Long seconds = (System.currentTimeMillis() / 1000); System.out.println("&gt;&gt;&gt;" + seconds); String stSeconds = seconds.toString(); OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.viagogo.net/Public /SimpleOAuthAccessRequest"); request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "My consumer key"); request.addOAuthParameter(OAuthConstants.NONCE, "myn0nc3"); request.addOAuthParameter(OAuthConstants.SIGN_METHOD, "HMAC-SHA1"); request.addOAuthParameter(OAuthConstants.TIMESTAMP, seconds.toString()); request.addOAuthParameter(OAuthConstants.VERSION, "1.0"); request.addOAuthParameter("scope", "API.Public"); 1 String signature = oauthService.signRequest(OAuthConstants.EMPTY_TOKEN, request); 2 request.addOAuthParameter(OAuthConstants.SIGNATURE,signature); Response response = request.send(); System.err.println("&gt;&gt;" + response.isSuccessful()); System.err.println("&gt;&gt;" + response.getMessage()); System.err.println("&gt;&gt;" + response.getBody()); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload