0

我使用以下代码发布到 Twitter。但是我11-06 17:11:28.811: D/Twitter Update Error(22688): No authentication challenges found在 logcat 中遇到错误,并且没有发布状态。相同的代码适用于另一个应用程序。

更新:

在我的应用程序中,任何数量的用户都可以通过 Twitter 注册。成功登录后,我曾经为特定用户将两个令牌存储在 db 中。如果其他用户喜欢通过 Twitter 分享,我会重置 accesstoken,并允许出现登录对话框,并存储该用户的令牌。如果特定用户的 db 中存在令牌,我直接从 db 获取令牌并使用它。

try {
                ConfigurationBuilder builder = new ConfigurationBuilder();
                builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
                builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

                // Access Token
                access_token = mSharedPreferences.getString(
                        PREF_KEY_OAUTH_TOKEN, "");
                // Access Token Secret
                access_token_secret = mSharedPreferences.getString(
                        PREF_KEY_OAUTH_SECRET, "");

                AccessToken accessToken = new AccessToken(access_token,
                        access_token_secret);
                Twitter twitter = new TwitterFactory(builder.build())
                        .getInstance(accessToken);

                // Update status
                twitter4j.Status response = twitter.updateStatus(status);

                Log.d("Status", "> " + response.getText());
            } catch (TwitterException e) {
                // Error in updating status
                Log.d("Twitter Update Error", e.getMessage());
            }
4

2 回答 2

0

尝试这个 :

        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthAccessToken("ACCESS_TOKEN");
        builder.setOAuthAccessTokenSecret("TOKEN_SECRET");
        builder.setOAuthConsumerKey("CLIENT_ID");
        builder.setOAuthConsumerSecret("CLIENT_SECRET");
        OAuthAuthorization auth = new OAuthAuthorization(builder.build());
        Twitter twitter = new TwitterFactory().getInstance(auth);
        twitter.updateStatus("TEXT TO POST");
于 2013-11-07T03:56:37.607 回答
0
// try this
               try {

                    // Access Token
                    access_token = mSharedPreferences.getString(
                            PREF_KEY_OAUTH_TOKEN, "");
                    // Access Token Secret
                    access_token_secret = mSharedPreferences.getString(
                            PREF_KEY_OAUTH_SECRET, "");

                    AccessToken accessToken = new AccessToken(access_token,
                            access_token_secret);
                    final Twitter twitter = new TwitterFactory().getInstance();
                    twitter.setOAuthConsumer("twitterConsumerKey", "twitterSecreatKey");
                    twitter.setOAuthAccessToken(accessToken);

                    // Update status
                    twitter4j.Status response = twitter.updateStatus(status);

                    Log.d("Status", "> " + response.getText());
                } catch (TwitterException e) {
                    // Error in updating status
                    Log.d("Twitter Update Error", e.getMessage());
                }
于 2013-11-06T13:00:24.317 回答