List of usage examples for twitter4j.auth OAuthAuthorization getOAuthRequestToken
@Override public RequestToken getOAuthRequestToken(String callbackURL) throws TwitterException
From source file:inujini_.hatate.service.OauthService.java
License:MIT License
/** * Oauth?.//from w ww.ja v a 2s . c o m * @param intent * @throws IllegalStateException intent?consumerKey?consumerKey???????????. */ private void startOauth(Intent intent) { // validate if (!intent.hasExtra(KEY_CONSUMER_KEY) || !intent.hasExtra(KEY_CONSUMER_SECRET)) { IllegalStateException e = new IllegalStateException( "In startOauth, intent's extra must have consumerKey and consumerSecret."); CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e); sendBroadcast(CallbackBroadcastReceiver.createIntent(data)); return; } Configuration conf = new ConfigurationBuilder().setOAuthConsumerKey(intent.getStringExtra(KEY_CONSUMER_KEY)) .setOAuthConsumerSecret(intent.getStringExtra(KEY_CONSUMER_SECRET)).build(); OAuthAuthorization oauth = new OAuthAuthorization(conf); oauth.setOAuthAccessToken(null); // ?URI? String uri; try { uri = oauth.getOAuthRequestToken(URI_CALLBACK).getAuthorizationURL(); } catch (TwitterException e) { e.printStackTrace(); CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e); sendBroadcast(CallbackBroadcastReceiver.createIntent(data)); return; } // OAuthAuthorization? try { serialize(oauth, "oauth.dat"); } catch (IOException e) { e.printStackTrace(); CallbackBroadcastReceiver.Data data = CallbackBroadcastReceiver.Data.create(e); sendBroadcast(CallbackBroadcastReceiver.createIntent(data)); return; } Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); }