androidtwitter4jandroid-twitter

How to tweet in android app?


I want to tweet on android app. I create app in adroid and I give permission read and write. I get tokens and consumer keys, And I write this code :

String token ="<Your access token>"; 
        String secret = "<Your access token secret>";
        AccessToken a = new AccessToken(token,secret);
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer("<Your consumer key>", "<Your consumer secret>");
        twitter.setOAuthAccessToken(a);
        try {
            twitter.updateStatus("android test");
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

But it gives error :

403:The request is understood, but it has been refused. 
An accompanying error message will explain why. 
This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
Relevant discussions can be on the Internet at:
    http://www.google.co.jp/search?q=b2b52c28 
    or
    http://www.google.co.jp/search?q=1b442886
TwitterException{exceptionCode=[b2b52c28-1b442886], statusCode=403, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}

how can I solve this?


Solution

  • You are getting this exception might be because of the earlier versioned twitter4j library. I suggest you to upgrade the library to latest version (twitter4j-core-3.0.5.jar).

    Download twitter4j-core-3.0.5.jar