简体   繁体   中英

twitter4j: getting access token based on twitter callback url

I have an android app that has an activity flow as follows:

1. Go to main activity, click Login button
2. Get redirected to the Twitter OAuth page
3. Have my app handle a URL like the one below:
oauth://com.galebach.Twitter_oAuth?oauth_token=xnpuie0lmqoPCAvdeitL0CTBgHogwj09nlDbATEk&oauth_verifier=dWMekKAb9aig3ja7skuzXY9SOP9QLZlRbJjLW5UOM

My question is, how can I use the token and verifier in that URL to get a Twitter AccessToken? The problem is that while I have the oauth_token, all of the functions for getting access tokens seem to want RequestTokens and a verifier as input, and I don't know how to build a RequestToken out of the raw string in the URI.

Now is required to use the Oauth_provider parameter, you can do it this way:

public static final String CALLBACK_URI = "http://www.yoururl.com/";

public static final String OAUTH_VERIFIER = "oauth_verifier";

String verifier = null;

if (uri != null && uri.toString().startsWith(Twitter.CALLBACK_URI)) 
verifier = uri.getQueryParameter(Twitter.OAUTH_VERIFIER);

AccessToken at = mTwitter.getOAuthAccessToken(mRequestToken, verifier);

I hope this helps you. Hector

You can get Access token this way:

        TwitterUtility twitterUtility = new TwitterUtility("CLIENT_ID","cLIENT_SECRET");
        AccessToken accessToken = twitterUtility.getAccessToken("OAUTH_TOKEN","Oauth_Verifier");

Ouath_token and oauth_verifier can be retrieved from the url itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM