Note that there are some explanatory texts on larger screens.

plurals
  1. POerror getting access token in twitter android app
    text
    copied!<p>i am using twitter4j in android application. i am using code with my consumer key and secret and when i logs in to twitter ,it successfully logs in at first try. but when i run the code again and then try,as i was previously authenticated,it logs me in but then gives 'error getting access token'. i don't understand how to deal with it.. can anybody please help.. i am using this code for login</p> <pre><code> public class TwitterLoginActivity extends Activity { TextView tv; Button loginBtn; private TwitterApp mTwitter; private ConnectionDetector cd; ProgressDialog pDialog; private static SharedPreferences mSharedPreferences; AlertDialogManager alert = new AlertDialogManager(); RequestToken requestToken; private static final String CONSUMER_KEY = "*****************"; private static final String CONSUMER_SECRET = "*****************************************"; static String PREFERENCE_NAME = "twitter_oauth"; static final String PREF_KEY_OAUTH_TOKEN = "oauth_token"; static final String PREF_KEY_OAUTH_SECRET = "oauth_token_secret"; static final String PREF_KEY_TWITTER_LOGIN = "isTwitterLogedIn"; static final String URL_TWITTER_AUTH = "auth_url"; static final String URL_TWITTER_OAUTH_VERIFIER = "oauth_verifier"; static final String URL_TWITTER_OAUTH_TOKEN = "oauth_token"; public void storeAccessToken(AccessToken aToken) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString(PREF_KEY_OAUTH_TOKEN, aToken.getToken()); editor.putString(PREF_KEY_OAUTH_SECRET, aToken.getTokenSecret()); editor.commit();} private enum FROM { TWITTER_POST, TWITTER_LOGIN }; private enum MESSAGE { SUCCESS, DUPLICATE, FAILED, CANCELLED }; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub setContentView(R.layout.twitter_login); super.onCreate(savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy); mTwitter = new TwitterApp(this, CONSUMER_KEY, CONSUMER_SECRET); requestToken = mTwitter.getOAuthRequestToken; tv = (TextView) findViewById(R.id.welcome_txt); loginBtn = (Button) findViewById(R.id.login_btn); loginBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mTwitter.setListener(mTwLoginDialogListener); mTwitter.resetAccessToken(); if (mTwitter.hasAccessToken() == true) { postAsToast(null, null); } else { mTwitter.authorize(); } } }); } private void postAsToast(FROM twitterPost, MESSAGE success) { switch (twitterPost) { case TWITTER_LOGIN: switch (success) { case SUCCESS: Toast.makeText(this, "Login Successful", Toast.LENGTH_LONG).show(); break; case FAILED: Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show(); default: break; } break; } } private TwDialogListener mTwLoginDialogListener = new TwDialogListener() { public void onError(String value) { postAsToast(FROM.TWITTER_LOGIN, MESSAGE.FAILED); Log.e("TWITTER", value); mTwitter.resetAccessToken(); } public void onComplete(String value) { Intent intent = new Intent(TwitterLoginActivity.this, TweetsListActivity.class); startActivity(intent); finish(); } }; } i have also used AlertDialogManager.java,ConnectionDetector.java classes in right manner. please help </code></pre>
 

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