2012-02-15 53 views
1

我正在嘗試在我的Android應用程序中整合Twitter。我檢查Android10和abhinavblog的代碼,我已經改變了只CONSUMER_KEY和CONSUMER_SECRET但我發現了錯誤的代碼 -在我的Android應用程序中整合Twitter時發生錯誤

@Override 
    protected Void doInBackground(Void... params) { 

     try { 
      Log.i(TAG, "Retrieving request token from Google servers"); 
      final String url = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL); 
      Log.i(TAG, "Popping a browser with the authorize URL : " + url); 
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND); 
      context.startActivity(intent); 
     } catch (Exception e) { 
      Log.e(TAG, "Error during OAUth retrieve request token", e); 
     } 

     return null; 
    } 

logcat的這個錯誤是 - 塊

$02-22 11:24:48.012: W/KeyCharacterMap(515): No keyboard for id 0 
    02-22 11:24:48.012: W/KeyCharacterMap(515): Using default keymap:    /system/usr/keychars/qwerty.kcm.bin 
02-22 11:24:53.343: I/com.ecs.android.sample.twitter.PrepareRequestTokenActivity(515): Starting task to retrieve request token. 
02-22 11:24:53.352: I/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): Retrieving request token from Google servers 
02-22 11:24:54.374: D/dalvikvm(515): GC_FOR_MALLOC freed 10292 objects/500672 bytes in 91ms 
02-22 11:24:54.493: D/dalvikvm(515): GC_FOR_MALLOC freed 2064 objects/289696 bytes in 71ms 
02-22 11:24:54.503: D/NativeCrypto(515): Freeing OpenSSL session 
02-22 11:24:55.022: W/DefaultRequestDirector(515): Authentication error: Unable to respond to any of these challenges: {} 
02-22 11:24:55.022: I/global(515): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): Error during OAUth retrieve request token 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match. 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:55) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at com.ecs.android.sample.twitter.OAuthRequestTokenTask.doInBackground(OAuthRequestTokenTask.java:1) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at android.os.AsyncTask$2.call(AsyncTask.java:185) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 
02-22 11:24:55.022: E/com.ecs.android.sample.twitter.OAuthRequestTokenTask(515): at java.lang.Thread.run(Thread.java:1096) 

爲什麼驗證錯誤:無法應對任何這些挑戰:{}爲空?

我給Twitter應用程序註冊的讀寫權限。

任何幫助將不勝感激。

回答

1

您的CONSUMER_KEY和CONSUMER_SECRET不正確,它們應該是您在Twitter上註冊的應用程序。

+0

專業。但是我已經在Twitter上註冊過的應用程序提供了正確的密鑰,即使我已經嘗試過重置密鑰選項。而且我還在Twitter上註冊了一個新的應用程序,並且使用了新密鑰並在我的代碼中進行了更改,同時我也得到了相同的錯誤。我被困在這裏totaly。請幫助 – 2012-02-15 07:43:18

+0

Chk出這個問題,你可能會得到一些解決方案,http://stackoverflow.com/questions/3315669/android-twitter-retrieveretoken_401-on-request-token – voidRy 2012-02-15 08:32:42

+0

感謝您的快速回復,你可以告訴我使用CALLBACK URL。我應該寫什麼,註冊應用程序到Twitter網站,應該在java文件中,什麼應該在XML文件中 – 2012-02-15 09:29:39