简体   繁体   English

twitter4j:基于Twitter回调URL获取访问令牌

[英]twitter4j: getting access token based on twitter callback url

I have an android app that has an activity flow as follows: 我有一个具有以下活动流程的android应用程序:

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? 我的问题是,如何使用该URL中的令牌和验证程序来获取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. 问题是,尽管我拥有oauth_token,但用于获取访问令牌的所有功能似乎都希望将RequestToken和验证程序作为输入,而且我不知道如何从URI的原始字符串中构建RequestToken。

Now is required to use the Oauth_provider parameter, you can do it this way: 现在需要使用Oauth_provider参数,您可以通过以下方式进行操作:

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. 可以从URL本身检索Ouath_token和oauth_verifier。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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