2013-03-10 66 views
0

我按照本教程http://www.javacodegeeks.com/2012/03/twitter-api-on-your-java-application.html做了完全相同的事情。但是我收到了一个如下所示的错误。我错过了什么吗?我应该在任何文件中设置一些权限吗?我检查了很多地方,但仍无法解决这个问题。请帮助如何使用Twitter4j显示推文

Exception in thread "main" 401:Authentication credentials 
(https://dev.twitter.com/docs/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?  
TwitterException{exceptionCode=[ced778ef-115a04e4], statusCode=401, retryAfter=-1, 
rateLimitStatus=RateLimitStatusJSONImpl{remainingHits=145, hourlyLimit=150, 
resetTimeInSeconds=1362901, secondsUntilReset=1235, resetTime=Sun Mar 10 13:15:51 IST 
2013}, featureSpecificRateLimitStatus=null, version=2.2.5} 
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:185) 
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) 
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:85) 
at twitter4j.TwitterImpl.get(TwitterImpl.java:1895) 
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:254) 
at com.jdwb.twitterapi.tweet.main(tweet.java:33) 

public class tweet { 
    public static void main(String[] args) throws TwitterException { 
     Twitter twitter = new TwitterFactory().getInstance(); 

     ResponseList <Status> a = twitter.getUserTimeline(new Paging(1, 5)); 
     for (Status b: a) { 
      System.out.println(b.getText()); 
     } 
    } 
} 



-------------------------Properties file------------- 

debug=true 
oauth.consumerKey=*************** 
oauth.consumerSecret=*********** 
oauth.accessToken=******************* 
oauth.accessTokenSecret=*********************** 

[Sun Mar 10 14:41:26 IST 2013]status: 401 Unauthorized 
[Sun Mar 10 14:41:26 IST 2013]x-ratelimit-remaining: 143 
[Sun Mar 10 14:41:26 IST 2013]content-encoding: gzip 
[Sun Mar 10 14:41:26 IST 2013]date: Sun, 10 Mar 2013 09:11:26 GMT 
[Sun Mar 10 14:41:26 IST 2013]x-ratelimit-reset: 1362908664 
[Sun Mar 10 14:41:26 IST 2013]x-transaction: 58f6c286bb1aa6de 
[Sun Mar 10 14:41:26 IST 2013]pragma: no-cache 
[Sun Mar 10 14:41:26 IST 2013]cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0 
[Sun Mar 10 14:41:26 IST 2013]{"request":"\/1\/statuses\/user_timeline.json?include_rts=true&include_entities=true&include_my_retweet=1&count=5&page=1","error":"Not authorized"} 

Exception in thread "main" 401:Authentication credentials 
(https://dev.twitter.com/docs/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 

回答

1

我假定你没有得到你的授权设置正确

对如何设置属性文件一看here

您需要注册twitter dev以获取您的API密钥,以便您可以填写所需的信息。

+0

嗨,感谢您的回复。我已经从twitter获得钥匙。我在项目中添加了一个twitter4j.properties文件,并添加了该链接中显示的键。现在,我收到了这个错误“消费者密钥/密钥对已设置” – 2013-03-10 08:46:34

+0

您是否在属性文件和代码中设置了密钥? – robthewolf 2013-03-10 08:57:35

+0

请检查我的编辑。我已经发布了代码 – 2013-03-10 09:04:36