Reputation: 2520
I try to use getUserTimeline() from Twitter4J library to download public tweets and it only works on some accounts. For example:
twitter.getUserTimeline("twitter"); //works
twitter.getUserTimeline("codeacademy"); //fails
However, I can't find any difference between the two. I am followed by none of them nor do I follow any. If I visit their accounts in Firefox's private mode, I am able to see their public tweets. It is the same when I login with my account. However, if I try to use API, codeacademy somehow fails. I tried calling it with argument "codeacademy", "Codeacademy", even with ID (716547158), always with the same results.
Error message I get is:
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\/statuses\/user_timeline.json?screen_name=codeacademy&include_my_retweet=true&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=00df323f or
http://www.google.co.jp/search?q=445fb8e5
TwitterException{exceptionCode=[00df323f-445fb8e5], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=177, limit=180, resetTimeInSeconds=1384522960, secondsUntilReset=495}, version=3.0.4}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:162)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:81)
...etc...
I've thought I may be initializing Twitter object wrong, but trying 3 different options didn't help. Here is what I've tried.
in twitter4j.properties (* are actual values there :))
oauth.consumerKey=***
oauth.consumerSecret=***
oauth.accessToken=***
oauth.accessTokenSecret=***
in java
Twitter twitter = TwitterFactory.getSingleton();
in twitter4j.properties
enableApplicationOnlyAuth=true
http.useSSL=true
oauth.consumerKey=***
oauth.consumerSecret=***
oauth2.tokenType=bearer
oauth2.accessToken=***
I got oauth2 values by calling and manually copy-pasting from:
OAuth2Token token = twitter.getOAuth2Token();
System.out.println(token.getAccessToken());
System.out.println(token.getTokenType());
in java
Twitter twitter = new TwitterFactory().getSingleton();
in twitter4j.properties
*nothing*
in java
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setUseSSL(true);
builder.setApplicationOnlyAuthEnabled(true);
Twitter twitter = new TwitterFactory(builder.build()).getInstance();
twitter.setOAuthConsumer("***", "***");
OAuth2Token token = twitter.getOAuth2Token();
Every attempt worked with twitter, none worked with codeacademy.
I must be doing something wrong but am not able to find out what. Any advice would be highly appreciated :). Thanks.
Upvotes: 3
Views: 1359
Reputation: 5149
When you go here: https://twitter.com/codeacademy
Its written on the page itself , that the tweets of this user are protected, only the followers have the access to the tweets of this account.
Hence, you can get the tweets:
Upvotes: 2