Get Accestoken of logged in user in twitter using twitter4j android -


i can log in twitter using twitter4j in android. when logged in, want accesstoken of logged in user. see below code.

uri uri = getintent().getdata();      if (uri != null && uri.tostring().startswith(twitter_callback_url)) {          string verifier = uri.getqueryparameter(twitter_oauth_verifier);          try {             accesstoken accesstoken = twitter.getoauthaccesstoken(requesttoken, verifier);             editor e = msharedpreferences.edit();              e.putstring(pref_key_oauth_token, accesstoken.gettoken());             e.putstring(pref_key_oauth_secret, accesstoken.gettokensecret());             e.putboolean(pref_key_twitter_login, true);             e.commit();              functiontocall(accesstoken);           }         catch (exception e) {         }     }     else{         //here program goes when user logged in.         //i want access token here (accesstoken object not string)         can pass function          functiontocall(accesstoken);             }     logintotwitter(); }  private void logintotwitter() {     // check if logged in     if (!istwitterloggedinalready()) {         configurationbuilder builder = new configurationbuilder();         builder.setoauthconsumerkey(twitter_consumer_key);         builder.setoauthconsumersecret(twitter_consumer_secret);         configuration configuration = builder.build();          twitterfactory factory = new twitterfactory(configuration);         twitter = factory.getinstance();         try {             requesttoken = twitter.getoauthrequesttoken(twitter_callback_url);             twitterlogin.this.startactivity(new intent(intent.action_view, uri.parse(requesttoken.getauthenticationurl())));         } catch (twitterexception e) {             e.printstacktrace();         }     } else {         //i want access token object either here or @ above code         //i can access token string (but want accesstoken object not string)         log.e("twitter oauth token", "> " + msharedpreferences.getstring(pref_key_oauth_token, "0"));     } } 

any appreciated. thanks.

getting preferences on android done sharedpreferences can preferencemanager.

use code settings , recreate accesstoken:

sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(contextintask); string token = prefs.getstring(pref_key_oauth_token, ""); string secret = prefs.getstring(pref_key_oauth_secret, "");  accesstoken token = new accesstoken(token, secret); 

if happen have (twitter) userid can use:

accesstoken token = new accesstoken(token, secret, userid); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -