在我的Android应用程序中集成Twitter时出错

时间:2012-02-15 06:26:29

标签: android twitter-oauth

我正在尝试将Twitter集成到我的Android应用程序中。我已经检查了Android10和abhinavblog的代码,我只更改了CONSUMER_KEY和CONSUMER_SECRET,但我从这段代码中得到错误 -

 @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 个答案:

答案 0 :(得分:1)

您的CONSUMER_KEY和CONSUMER_SECRET不正确,它们应该是您在Twitter上注册的应用程序。