2013-02-13 49 views
5

我對谷歌的AppEngine下面的代碼來測試如果Twitter憑證使用twitter4jTwitter4J驗證憑據和追趕的錯誤

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。爲什麼?我無法在javadoc中找到任何TwitterRuntimeException的註釋。

+0

Hiii ,,,,你有沒有找到解決方案? @邁克爾.. – 2013-07-29 10:27:59

+0

發現任何解決方案? – 2013-09-11 00:17:21

回答

1

對我來說,解決辦法是如下:

  • 轉到您的twitter app
  • 選擇設置選項卡
  • 根據應用類型 - 訪問 - 選擇最後一個選項讀,寫 和訪問直接消息

如果這不能解決問題,請嘗試添加回撥URL。你可以把任何網址,這將是罰款。

+1

正是我所需要的。添加回調網址是我缺少的一塊 – 2014-11-08 17:37:55