//The consumer object was lost because the browser got into foreground, need to instantiate it again with your apps token and secret. consumer = new CommonsHttpOAuthConsumer("xxx", "yyy"); //Set the requestToken and the tokenSecret that you got earlier by calling retrieveRequestToken. consumer.setTokenWithSecret(requestToken, tokenSecret); //The provider object is lost, too, so instantiate it again. provider = new CommonsHttpOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize"); //Now that's really important. Because you don't perform the retrieveRequestToken method at this moment, the OAuth method is not detected automatically (there is no communication with Twitter). So, the default is 1.0 which is wrong because the initial request was performed with 1.0a. provider.setOAuth10a(true); provider.retrieveAccessToken(consumer, verifier);
@Override public OAuthProvider getProvider() throws ConnectionException { CommonsHttpOAuthProvider provider = null; provider = new CommonsHttpOAuthProvider(getApiUrl(ApiRoutineEnum.OAUTH_REQUEST_TOKEN), getApiUrl(ApiRoutineEnum.OAUTH_ACCESS_TOKEN), getApiUrl(ApiRoutineEnum.OAUTH_AUTHORIZE)); provider.setHttpClient(ApacheHttpClientUtils.getHttpClient(data.getSslMode())); provider.setOAuth10a(true); return provider; }
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); CommonsHttpOAuthProvider provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_URL); provider.setOAuth10a(true); Map<String, String> requestHeaders = provider.getRequestHeaders(); requestHeaders.put("User-Agent", USER_AGENT); requestHeaders.put("Accept-Encoding", "gzip"); String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
commonsHttpOAuthProvider = new CommonsHttpOAuthProvider(TWITTER_OAUTH_REQUEST_TOKEN_ENDPOINT, TWITTER_OAUTH_ACCESS_TOKEN_ENDPOINT, TWITTER_OAUTH_AUTHORIZE_ENDPOINT); commonsHttpOAuthConsumer = new CommonsHttpOAuthConsumer(getString(R.string.twitter_oauth_consumer_key), getString(R.string.twitter_oauth_consumer_secret)); commonsHttpOAuthProvider.setOAuth10a(true); TwDialog dialog = new TwDialog(this, commonsHttpOAuthProvider, commonsHttpOAuthConsumer, dialogListener, R.drawable.android);
String access_token_url = TWITTER_ACCESS_TOKEN_URL; String authorize_url = TWITTER_AUTHORZE_URL; mHttpOauthprovider=new CommonsHttpOAuthProvider(request_url, access_token_url, authorize_url); authUrl = mHttpOauthprovider.retrieveRequestToken( mHttpOauthConsumer, CALLBACK_URL); mHttpOauthprovider.retrieveAccessToken(mHttpOauthConsumer, verifier); Toast.makeText(context, "new...", 87777).show();
this.mainProvider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_ENDPOINT_URL, ACCESS_TOKEN_ENDPOINT_URL, AUTHORIZE_WEBSITE_URL); protected Void doInBackground(Void... arg0) { try { mainProvider.retrieveAccessToken(mainConsumer, oAuthVerifier); } catch (OAuthMessageSignerException e) { "Token = " + mainConsumer.getToken() + "<br>" + "secret = " + mainConsumer.getTokenSecret() + "<br>" + "oauth_expires_in = " + mainProvider.getResponseParameters().getFirst("oauth_expires_in") + "<br>" + "oauth_session_handle = " + mainProvider.getResponseParameters().getFirst("oauth_session_handle") + "<br>" + "oauth_authorization_expires_in = " + mainProvider.getResponseParameters().getFirst("oauth_authorization_expires_in") + "<br>" + "xoauth_yahoo_guid = " + mainProvider.getResponseParameters().getFirst("xoauth_yahoo_guid") + "<br>"; Log.i("YahooScreen", "str : " + str); String guid = mainProvider.getResponseParameters().getFirst("xoauth_yahoo_guid"); String url = "https://social.yahooapis.com/v1/user/" + guid + "/profile?format=json"; this.doGet(url);
/** * Use a specific {@link HttpClient} for HTTP traffic. * * @param httpClient {@link HttpClient}, that is used for HTTP communication */ public synchronized void setHttpClient(HttpClient httpClient) { this.httpClient = httpClient; // register HTTP client in the OAuth provider try { OAuthProvider p = getAuthProvider(); if (p instanceof CommonsHttpOAuthProvider) { ((CommonsHttpOAuthProvider) p).setHttpClient(httpClient); } } catch (OAuthNotAuthorizedException ex) { } } }
@Override protected Void doInBackground(Void... params) { try { requestTokenUrl = oAuthProvider.retrieveRequestToken(oAuthConsumer, callbackUrl); } catch (OAuthException oe) { Log.e(TAG, "Could not retrieve request token", oe); oAuthException = oe; cancel(false); } return null; }
@Override protected Void doInBackground(Void... params) { try { oAuthProvider.retrieveAccessToken(oAuthConsumer, verifier); // Store token in preferences for future use SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); Editor editor = prefs.edit(); editor.putString(OSMTracker.Preferences.KEY_OSM_OAUTH_TOKEN, oAuthConsumer.getToken()); editor.putString(OSMTracker.Preferences.KEY_OSM_OAUTH_SECRET, oAuthConsumer.getTokenSecret()); editor.commit(); } catch (OAuthException oe) { Log.e(TAG, "Could not retrieve access token", oe); oAuthException = oe; cancel(false); } return null; }
commonsHttpOAuthProvider = new CommonsHttpOAuthProvider(TWITTER_OAUTH_REQUEST_TOKEN_ENDPOINT, TWITTER_OAUTH_ACCESS_TOKEN_ENDPOINT, TWITTER_OAUTH_AUTHORIZE_ENDPOINT); commonsHttpOAuthConsumer = new CommonsHttpOAuthConsumer(getString(R.string.twitter_oauth_consumer_key), getString(R.string.twitter_oauth_consumer_secret)); commonsHttpOAuthProvider.setOAuth10a(true); TwDialog dialog = new TwDialog(this, commonsHttpOAuthProvider, commonsHttpOAuthConsumer, dialogListener, R.drawable.android);
/** * Use a specific {@link HttpClient} for HTTP traffic. * * @param httpClient * {@link HttpClient}, that is used for HTTP communication */ public synchronized void setHttpClient( HttpClient httpClient ) { this.httpClient = httpClient; // register HTTP client in the OAuth provider try { OAuthProvider p = getAuthProvider(); if (p instanceof CommonsHttpOAuthProvider) { ((CommonsHttpOAuthProvider) p).setHttpClient( httpClient ); } } catch (OAuthNotAuthorizedException ex) { } } }
@Override protected OAuthProvider buildProvider(String requestTokenUrl, String accessTokenUrl, String websiteUrl, boolean mockConnection) throws Exception { if (mockConnection) { CommonHttpOAuthProviderMock provider = new CommonHttpOAuthProviderMock(requestTokenUrl, accessTokenUrl, websiteUrl); provider.mockConnection(OAuth.OAUTH_TOKEN + "=" + TOKEN + "&" + OAuth.OAUTH_TOKEN_SECRET + "=" + TOKEN_SECRET); return provider; } return new CommonsHttpOAuthProvider(requestTokenUrl, accessTokenUrl, websiteUrl); } }
/** * Use a specific {@link HttpClient} for HTTP traffic. * * @param httpClient * {@link HttpClient}, that is used for HTTP communication */ public synchronized void setHttpClient( HttpClient httpClient ) { this.httpClient = httpClient; // register HTTP client in the OAuth provider try { OAuthProvider p = getAuthProvider(); if (p instanceof CommonsHttpOAuthProvider) { ((CommonsHttpOAuthProvider) p).setHttpClient( httpClient ); } } catch (OAuthNotAuthorizedException ex) { } } }
@Override protected OAuthProvider buildOAuthProvider( String apiBaseUrl ) { if (httpClient==null) setDefaultHttpClient(); return new CommonsHttpOAuthProvider( apiBaseUrl + "/security/oauth/request_token", apiBaseUrl + "/security/oauth/access_token", apiBaseUrl + "/security/oauth/confirm_access", httpClient ); }
@Override protected OAuthProvider buildOAuthProvider(String apiBaseUrl) { if (httpClient == null) setDefaultHttpClient(); return new CommonsHttpOAuthProvider( apiBaseUrl + "/security/oauth/request_token", apiBaseUrl + "/security/oauth/access_token", apiBaseUrl + "/security/oauth/confirm_access", httpClient); }
public OAuth(ServiceInfo info, boolean use10a) { this.info = info; this.provider = new CommonsHttpOAuthProvider(info.requestTokenURL, info.accessTokenURL, info.authorizationURL); this.provider.setOAuth10a(use10a); }
public OAuth(ServiceInfo info, boolean use10a) { this.info = info; this.provider = new CommonsHttpOAuthProvider(info.requestTokenURL, info.accessTokenURL, info.authorizationURL); this.provider.setOAuth10a(use10a); }
@Override protected OAuthProvider buildOAuthProvider( String apiBaseUrl ) { if (httpClient==null) setDefaultHttpClient(); return new CommonsHttpOAuthProvider( apiBaseUrl + "/security/oauth/request_token", apiBaseUrl + "/security/oauth/access_token", apiBaseUrl + "/security/oauth/confirm_access", httpClient ); }
//Generate a new oAuthConsumer object commonsHttpOAuthConsumer = new CommonsHttpOAuthConsumer( "Consumer Key", "Consumer Secret Key"); //Generate a new oAuthProvider object commonsHttpOAuthProvider = new CommonsHttpOAuthProvider( "https://www.tumblr.com/oauth/request_token", "https://www.tumblr.com/oauth/access_token", "https://www.tumblr.com/oauth/authorize"); //Retrieve the URL to which the user must be sent in order to authorize the consumer return commonsHttpOAuthProvider.retrieveRequestToken( commonsHttpOAuthConsumer, "Callback URL as registered with Tumblr" );
mTwitter = new TwitterFactory().getInstance(); mHttpOauthConsumer = new CommonsHttpOAuthConsumer(twitterConsumerKey, twitterSecretKey); mHttpOauthprovider = new CommonsHttpOAuthProvider("https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token", "https://twitter.com/oauth/authorize"); try{ authUrl = mHttpOauthprovider.retrieveRequestToken(mHttpOauthConsumer, CALLBACK_URL); }catch(OAuthCommunicationException oACEx){ Log.d("", ""); }catch(OAuthMessageSignerException oAMSEx){ Log.d("", ""); }catch(OAuthNotAuthorizedException oANAEx){ Log.d("", ""); }catch(OAuthExpectationFailedException oAEFEx){ Log.d("", ""); }