Search code examples
androidtwitter4j

No authentication challenges found in Twitter post


I used the following code to post to Twitter. But I'm getting 11-06 17:11:28.811: D/Twitter Update Error(22688): No authentication challenges found error in logcat and status doesn't get posted. The same code works in another application.

update:

In my app any number of users can register through Twitter. I used to store both the tokens in db for a particular user after successful login. If different user likes to share through Twitter, I reset the accesstoken, and allow the login dialog to appear, and store that users tokens. If tokens are present in the db for a particular user, I directly get the tokens from db and used that.

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());
            }

Solution

  • // 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());
                    }