我在 google appengine 上有以下代码来测试 twitter 凭据是否使用 twitter4j 有效
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
String Test = "Testing Twitter4J";
try {
ConfigurationBuilder confbuilder = new ConfigurationBuilder();
confbuilder.setOAuthAccessToken("A")
.setOAuthAccessTokenSecret("B")
.setOAuthConsumerKey("C")
.setOAuthConsumerSecret("D");
Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance();
//Status status = twitter.updateStatus("Working lunch today");
User user = twitter.verifyCredentials();
Test = "Successfully updated the status to [" + user.getScreenName() + "].";
} catch (TwitterException e) {
Test = "no";
}
try {
resp.getOutputStream().write(Test.getBytes());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
如果凭据有效,它将按预期工作。如果我撤销访问权限导致凭据无效,我会收到应用引擎错误:
Uncaught exception from servlet
twitter4j.TwitterRuntimeException: 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.
message - Invalid or expired token
code - 89
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=93f2523c or
http://www.google.co.jp/search?q=8b74a4e3
TwitterException{exceptionCode=[93f2523c-8b74a4e3], statusCode=401, message=Invalid or expired token, code=89, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
来自“用户用户 = twitter.verifyCredentials();” 线。我期待从 javadoc 中抛出 TwitterException:http: //twitter4j.org/javadoc/twitter4j/api/UsersResources.html#verifyCredentials() 但似乎我得到了 TwitterRuntimeException。为什么?我在 javadocs 中找不到任何关于 TwitterRuntimeException 的注释。