【问题标题】:How to send a tweet with jTwitter on Android?如何在 Android 上使用 jTwitter 发送推文?
【发布时间】:2012-05-19 16:14:51
【问题描述】:

有没有人在 Android 上通过 jTwitter 成功发送过推文?

我被认证卡住了。我可以成功地将用户重定向到 Twitter,授权我的应用程序并使用new OAuthSignpostClient(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL) 重定向到我的应用程序。然后我存储与回调 URL 一起提供的 oauth_tokenoauth_verifier 并尝试再次使用 OAuthSignpostClient 来更新状态:

OAuthSignpostClient client = new OAuthSignpostClient(TwitterOAuthActivity.CONSUMER_KEY, TwitterOAuthActivity.CONSUMER_SECRET, accessToken, accessTokenSecret);

// Ready to go!
Twitter twitter = new Twitter(null, client);
CharSequence date = DateFormat.format("dd.MM.yyyy @ hh:mm:ss", new Date());
twitter.updateStatus("Yay. It works! " + date);

TwitterException 结尾而没有引起:

05-11 12:24:32.643: E/AndroidRuntime(25897): winterwell.jtwitter.TwitterException$E401: Could not authenticate with OAuth.
05-11 12:24:32.643: E/AndroidRuntime(25897): http://api.twitter.com/1/statuses/update.json (anonymous)
05-11 12:24:32.643: E/AndroidRuntime(25897):    at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:425) 
05-11 12:24:32.643: E/AndroidRuntime(25897):    at winterwell.jtwitter.OAuthSignpostClient.post2_connect(OAuthSignpostClient.java:345)

有人知道我的问题在哪里吗?

【问题讨论】:

    标签: android service oauth signpost jtwitter


    【解决方案1】:

    来自回调 url 的验证器是一个临时键。它让您解锁您拥有的 OAuthSignpostClient 对象。您不能使用它来构造新的 OAuthSignpostClient。

    您需要致电:

    client.setAuthorizationCode(verifier);
    // The client can now be used!
    // To use it again, without the oauth dance, store _these_ tokens:
    String[] tokens = client.getAccessToken();
    

    您可能还想查看新的 AndroidTwitterLogin 类,它使事情变得简单:

    AndroidTwitterLogin atl = new AndroidTwitterLogin(myApp, 
                    MY_TWITTER_KEY,MY_TWITTER_SECRET,MY_TWITTER_CALLBACK) {                 
    
        protected void onSuccess(Twitter jtwitter, String[] tokens) {
            jtwitter.setStatus("I can now post to Twitter!");
            // Recommended: store tokens in your app for future use
            // with the constructor OAuthSignpostClient(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret)
        }
    };
    atl.run();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-27
      • 2015-11-23
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多