0

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

我被身份验证困住了。我可以成功地将用户重定向到 twitter,授权我的应用程序并使用new OAuthSignpostClient(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL). 然后我存储oauth_tokenoauth_verifier回调 URL,并尝试再次使用 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);

以 a 结尾TwitterException而没有 a 由以下原因引起:

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)

有谁知道我的问题在哪里?

4

1 回答 1

0

来自回调 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();
于 2012-05-18T10:44:38.067 回答