Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter4j: getting inconcistent authentication errors when invoking getFollowersIDs

I am using Twitter4j version 3.0.3.

I am trying to pull follower id and using OAuth. I have been using Twitter4j for years and am relatively experienced with the framework.

However something strange is happening: My program will run fine and then intermittently throw the following stack trace:

Exception in thread "main" 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/followers\/ids.json?user_id=20801287&cursor=-1&include_entities=1&include_rts=1","error":"Not authorized"}

Relevant discussions can be found on the Internet at:
    http://www.google.co.jp/search?q=92c30ec6 or
    http://www.google.co.jp/search?q=19400604
TwitterException{exceptionCode=[92c30ec6-19400604], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=6, limit=15, resetTimeInSeconds=1362898120, secondsUntilReset=890}, version=3.0.3}
    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
    at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
    at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89)
    at twitter4j.TwitterImpl.get(TwitterImpl.java:1817)
    at twitter4j.TwitterImpl.getFollowersIDs(TwitterImpl.java:400)

It throws the above at the following line:

IDs ids= twitter.getFollowersIDs(id,cursor);

The above line executes just fine and then without warning fails.

Note: I am checking rate limits and the last time I encountered this the rate limit JSON object pulled by the following line was (below):

RateLimitStatus rls=twitter.getRateLimitStatus().get("/followers/ids")

RateLimitStatusJSONImpl{remaining=7, limit=15, resetTimeInSeconds=1362898120, secondsUntilReset=890}

I thought this might have been an intermittent thing with Twitter, but it has been going on for a few days now.

I've tried it from various machines but get exactly the same problem.

The call fails in this manner, once in approximately 20 calls.

I have also read the similar questions on SE:

  1. Twitter4j 401 Authentication -- However, this is a case where OAuth was not working -- in my case it seems to be working fine until of course when it doesn't.

  2. twitter4j: getting credential errors even though i had set them? -- again not much here that is similar to my case.

  3. Problem in Oauth with twitter4j -- suggest registering the app as a web-app, which I've done, I've filling in the callback url (though it does nothing), but still no luck.

like image 284
user1172468 Avatar asked Oct 22 '22 15:10

user1172468


1 Answers

The exception seems to be caused by ids of twitter profiles that may be private.

like image 68
user1172468 Avatar answered Oct 28 '22 15:10

user1172468