我正试图通过此代码获取Twitter用户的推文:
public void displayTweets() throws TwitterException{
uri = getIntent().getData();
System.out.println(uri);
verifier = uri.getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);
accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
long userID = accessToken.getUserId();
try {
Twitter twitter = new TwitterFactory().getInstance();
//List<Status> statuses = twitter.getRetweets(Long.parseLong(args[0]));
List<Status> statuses = twitter.getRetweets(userID);
for (Status status : statuses) {
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}
System.out.println("done.");
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get retweets: " + te.getMessage());
System.exit(-1);
}
}
不幸的是我没有得到任何显示,我得到了这个日志(使用LogCat):
Log-Cat:
06-25 12:55:43.811: W/System.err(24552): 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.
06-25 12:55:43.811: W/System.err(24552): <?xml version="1.0" encoding="UTF-8"?>
06-25 12:55:43.811: W/System.err(24552): <hash>
06-25 12:55:43.811: W/System.err(24552): <error>Invalid / expired Token</error>
06-25 12:55:43.811: W/System.err(24552): <request>/oauth/access_token</request>
06-25 12:55:43.811: W/System.err(24552): </hash>
06-25 12:55:43.811: W/System.err(24552): Relevant discussions can be found on the Internet at:
06-25 12:55:43.811: W/System.err(24552): http://www.google.co.jp/search?q=1aec76dd or
06-25 12:55:43.816: W/System.err(24552): http://www.google.co.jp/search?q=80621963
06-25 12:55:43.816: W/System.err(24552): TwitterException{exceptionCode=[1aec76dd-80621963], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.1}
06-25 12:55:43.816: W/System.err(24552): at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
06-25 12:55:43.816: W/System.err(24552): at twitter4j.HttpClientBase.request(HttpClientBase.java:53)
06-25 12:55:43.816: W/System.err(24552): at twitter4j.HttpClientBase.post(HttpClientBase.java:82)
06-25 12:55:43.816: W/System.err(24552): at twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:139)
06-25 12:55:43.816: W/System.err(24552): at twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorization.java:159)
06-25 12:55:43.816: W/System.err(24552): at twitter4j.TwitterBaseImpl.getOAuthAccessToken(TwitterBaseImpl.java:370)
06-25 12:55:43.816: W/System.err(24552): at com.androidhive.twitterconnect.MainActivity.afficherTweets(MainActivity.java:274)
06-25 12:55:43.816: W/System.err(24552): at com.androidhive.twitterconnect.MainActivity.onClick(MainActivity.java:411)
06-25 12:55:43.816: W/System.err(24552): at android.view.View.performClick(View.java:3620)
06-25 12:55:43.821: W/System.err(24552): at android.view.View$PerformClick.run(View.java:14292)
06-25 12:55:43.821: W/System.err(24552): at android.os.Handler.handleCallback(Handler.java:605)
06-25 12:55:43.821: W/System.err(24552): at android.os.Handler.dispatchMessage(Handler.java:92)
06-25 12:55:43.821: W/System.err(24552): at android.os.Looper.loop(Looper.java:137)
06-25 12:55:43.821: W/System.err(24552): at android.app.ActivityThread.main(ActivityThread.java:4507)
06-25 12:55:43.821: W/System.err(24552): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 12:55:43.821: W/System.err(24552): at java.lang.reflect.Method.invoke(Method.java:511)
06-25 12:55:43.821: W/System.err(24552): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
06-25 12:55:43.821: W/System.err(24552): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
06-25 12:55:43.821: W/System.err(24552): at dalvik.system.NativeStart.main(Native Method)