Search code examples
twitter4j

Twitter4j 401 Authentication Exception just when calling getFriendsList


twitter.verifyCredentials() //works fine and returns my account as a User
twitter.getFriendsList(someUserId, -1, 100) //throws exception

Authentication Exception:

twitter4j.TwitterException: 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\/friends\/list.json","error":"Not authorized."}

    at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:163) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
    at twitter4j.HttpClientBase.request(HttpClientBase.java:53) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
    at twitter4j.HttpClientBase.get(HttpClientBase.java:71) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
    at twitter4j.TwitterImpl.get(TwitterImpl.java:1544) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]
    at twitter4j.TwitterImpl.getFriendsList(TwitterImpl.java:474) ~[org.twitter4j.twitter4j-core-4.0.3.jar:4.0.3]

I synced the system clock. But this seems kind of odd since the verifyCredentials works fine but getFriendsList throws this exception. I also do some following/unfollowing with this account with this account which works fine.


Solution

  • Found the cause by myself:

    The user I was trying to get the followings from was protected. To get these followings you need to get authorized by the user.