我需要在Twitter上搜索关键字,我尝试使用下面的代码段,但它会引发身份验证错误:
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.
The screen name / password combination seems to be invalid.
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=96430884 or
http://www.google.co.jp/search?q=00002ebf
TwitterException{exceptionCode=[96430884-00002ebf 9aae86e9-153e2e3e], statusCode=401,
message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at
twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:187)
at twitter4j.TwitterBaseImpl.getOAuthAccessToken(TwitterBaseImpl.java:380)
scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: 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.
Failed to validate oauth signature and token
消费者密钥和密钥取自twitter中的应用程序访问详细信息。 我正在使用以下代码段:
try {
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("xxxxx", "xxxxx");
RequestToken twitterRequestToken = twitter.getOAuthRequestToken();
String token = twitterRequestToken.getToken();
String tokenSecret = twitterRequestToken.getTokenSecret();
AccessToken accessToken = twitter.getOAuthAccessToken(token, tokenSecret);
twitter.setOAuthAccessToken(accessToken);
Query query = new Query("source:twitter4j yusukey");
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
log.info("@" + status.getUser().getScreenName() + ":" + status.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
我是否设置了访问推文的必要细节?如果我在这里做错了,请告诉我......
感谢。