我目前正在尝试获取一堆用户的用户时间线。这在以前对我有用,但现在不再起作用。我正在使用twitter4j和oauth。到目前为止,我已经在我的账户上注册了2个应用程序,它们都应该能够访问twitter-api。然而,自昨天以来,无论是哪个应用程序,我都收到了一个401错误 - 身份验证凭据缺失或不正确。Twitter最近是否对API进行了任何更改?我应该设置一个新的Twitter账户吗?创建一个应用程序并允许其访问您自己的账户是否是适当的方法?
以下是代码:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("q...w")
.setOAuthConsumerSecret("R...o")
.setOAuthAccessToken("2...7")
.setOAuthAccessTokenSecret("O....8");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
for ( Map.Entry<Long, String> entry : tmls.entrySet()) {
long uid = entry.getKey();
Paging paging = new Paging(1, count);
ResponseList<Status> rls;
try {
rls = twitter.getUserTimeline(uid, paging);
for ( int j = 0 ; j < rls.size() ; j++ ) {
if (false == ltindex.contains(uid)) {
alsa.add(new String[] { String.valueOf( rls.get(j).getId() ) , String.valueOf( uid ), rls.get(j).getText() , "", entry.getValue(), String.valueOf( rls.get(j).getCreatedAt().getTime() ) });
}
}
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
错误:
401:Authentication credentials (http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
error - Not authorized
request - /1/statuses/user_timeline.json?user_id=14221532&include_rts=true&include_entities=false&count=10&page=1
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=ced778ef or
http://www.google.co.jp/search?q=10a1ea9d
TwitterException{exceptionCode=[ced778ef-10a1ea9d], statusCode=401, retryAfter=0, rateLimitStatus=RateLimitStatusJSONImpl{remainingHits=273, hourlyLimit=350, resetTimeInSeconds=1304422, secondsUntilReset=845, resetTime=Tue May 03 11:36:48 UTC 2011}, version=2.2.3-SNAPSHOT(build: ddf24547632bf3a28b899e3d75b110de43f71c0f)}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:85)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1738)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:246)
at getExpertTweets.getSpecificOpinions(getExpertTweets.java:89)
at classifyTweet.main(classifyTweet.java:57)
root@se1:~# sudo ntpdate pool.ntp.org