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

发布于 2025-01-05 05:55:22 字数 4147 浏览 0 评论 0原文

我正在尝试将 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 应用程序注册的读取和写入权限。

任何帮助将不胜感激。

I'm trying to integrate Twitter in my android application. I've checked Android10 and abhinavblog's code and I've changed just CONSUMER_KEY and CONSUMER_SECRET but I'm getting error from this block of code-

 @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 error is-

 $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)

Why Authentication error: Unable to respond to any of these challenges: {} is empty?

I've give Read and Write permission On Twitter Application registration.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单气质女生网名 2025-01-12 05:55:22

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

Your CONSUMER_KEY and CONSUMER_SECRET are not correct,they should be of application you have registered on twitter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文