【问题标题】:twitter4j: getting access token based on twitter callback urltwitter4j:根据 twitter 回调 url 获取访问令牌
【发布时间】:2013-10-23 09:19:25
【问题描述】:

我有一个 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

我的问题是,如何使用该 URL 中的令牌和验证器来获取 Twitter AccessToken?问题是,虽然我有 oauth_token,但所有获取访问令牌的函数似乎都需要 RequestTokens 和验证器作为输入,而且我不知道如何从 URI 中的原始字符串构建 RequestToken。

【问题讨论】:

    标签: android twitter twitter4j


    【解决方案1】:

    现在需要使用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);
    

    我希望这对你有帮助。 赫克托

    【讨论】:

      【解决方案2】:

      您可以通过这种方式获取访问令牌:

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

      Ouath_token 和 oauth_verifier 可以从 url 本身获取。

      【讨论】:

        猜你喜欢
        • 2015-09-07
        • 1970-01-01
        • 2013-08-10
        • 2012-02-10
        • 2012-12-29
        • 2022-11-28
        • 2013-03-30
        • 2016-07-18
        • 1970-01-01
        相关资源
        最近更新 更多