2

我需要在 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();
    }

我是否设置了访问推文所需的详细信息?如果我在这里做错了什么,请告诉我...

谢谢。

4

0 回答 0