Twitter4J + Android:身份验证质询为空异常

发布于 2024-11-09 20:45:39 字数 4256 浏览 4 评论 0原文

我正在使用 Twitter4J 库进行 OAuth 身份验证,但甚至在打开 Twitter 登录页面之前我就收到“身份验证挑战为空异常”。

这是代码。

    Twitter twitter = new TwitterFactory().getInstance();
    try
    {

        twitter.setOAuthConsumer(Startup.TWITTER_KEY, Startup.TWITTER_SECRET);

        String callbackURL = "twitter-client:///";

        RequestToken rToken = twitter.getOAuthRequestToken(callbackURL);

        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(rToken.getAuthenticationURL())));

    }
    catch(IllegalStateException e)
    {
    // access token is already available, or consumer key/secret is not set.
        if(!twitter.getAuthorization().isEnabled()){
            System.out.println("OAuth consumer key/secret is not set.");
            System.exit(-1);
        }
    }
    catch(Exception e)
    {
        Toast.makeText(Home.this, "Network Host not responding: "+e.getMessage(),Toast.LENGTH_SHORT).show();  //This exception. 
    }

例外:

E/Home (4393):已收到 身份验证质询为空 E/Home (4393):已收到 身份验证质询是 null相关讨论可以在 互联网地址:E/Home (4393): http://www.google.co.jp/search?q=6c607809 或电子/主页(4393): http://www.google.co.jp/search?q=0f1d8134 电子/主页(4393): TwitterException{异常代码=[6c607809-0f1d8134 cab4c0ac-d492a113],状态代码=-1, 重试后=0,rateLimitStatus=null, 版本=2.2.2} E/Home (4393):位于 twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:204) E/Home(4393):位于 twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65) E/Home(4393):位于 twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102) E/Home(4393):位于 twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:108) E/Home(4393):位于 twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:271) E/Home(4393):位于 com.sharj.trafik.view.Home.askOAuth(Home.java:157) E/Home(4393):位于 com.sharj.trafik.view.Home.access$0(Home.java:143) E/Home(4393):位于 com.sharj.trafik.view.Home$3.onClick(Home.java:110) E/Home(4393):位于 android.view.View.performClick(View.java:2485) E/Home(4393):位于 android.view.View$PerformClick.run(View.java:9080) E/Home(4393):位于 android.os.Handler.handleCallback(Handler.java:587) E/Home(4393):位于 android.os.Handler.dispatchMessage(Handler.java:92) E/Home(4393):位于 android.os.Looper.loop(Looper.java:130) E/Home(4393):位于 android.app.ActivityThread.main(ActivityThread.java:3683) E/Home(4393):位于 java.lang.reflect.Method.invokeNative(本机 方法)E/Home (4393):位于 java.lang.reflect.Method.invoke(Method.java:507) E/Home(4393):位于 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) E/Home(4393):位于 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) E/Home(4393):位于 dalvik.system.NativeStart.main(本机 方法)E/Home(4393): 原因: java.io.IOException:已收到 身份验证质询为空 E/Home(4393):位于 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153) E/Home(4393):位于 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:1095) E/Home(4393):位于 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1048) E/Home(4393):位于 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726) E/Home(4393):位于 org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:121) E/Home(4393):位于 twitter4j.internal.http.HttpResponseImpl。(HttpResponseImpl.java:35) E/Home(4393):位于 twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:168) E/Home ( 4393): ... 18 更多

它包含以下链接,但 Google 对此没有太多内容。

http://www.google.co.jp/search?q=6c607809

http://www.google.co.jp/search?q=0f1d8134

I'm using Twitter4J library for OAuth authentication but I get "Authentication Challenge is Null Exception" even before It opens the Twitter login page.

Here is the code.

    Twitter twitter = new TwitterFactory().getInstance();
    try
    {

        twitter.setOAuthConsumer(Startup.TWITTER_KEY, Startup.TWITTER_SECRET);

        String callbackURL = "twitter-client:///";

        RequestToken rToken = twitter.getOAuthRequestToken(callbackURL);

        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(rToken.getAuthenticationURL())));

    }
    catch(IllegalStateException e)
    {
    // access token is already available, or consumer key/secret is not set.
        if(!twitter.getAuthorization().isEnabled()){
            System.out.println("OAuth consumer key/secret is not set.");
            System.exit(-1);
        }
    }
    catch(Exception e)
    {
        Toast.makeText(Home.this, "Network Host not responding: "+e.getMessage(),Toast.LENGTH_SHORT).show();  //This exception. 
    }

Exception:

E/Home ( 4393): Received
authentication challenge is null
E/Home ( 4393): Received
authentication challenge is
nullRelevant discussions can be on the
Internet at: E/Home ( 4393):
http://www.google.co.jp/search?q=6c607809
or E/Home ( 4393):
http://www.google.co.jp/search?q=0f1d8134
E/Home ( 4393):
TwitterException{exceptionCode=[6c607809-0f1d8134
cab4c0ac-d492a113], statusCode=-1,
retryAfter=0, rateLimitStatus=null,
version=2.2.2} E/Home ( 4393): at
twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:204)
E/Home ( 4393): at
twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
E/Home ( 4393): at
twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
E/Home ( 4393): at
twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:108)
E/Home ( 4393): at
twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:271)
E/Home ( 4393): at
com.sharj.trafik.view.Home.askOAuth(Home.java:157)
E/Home ( 4393): at
com.sharj.trafik.view.Home.access$0(Home.java:143)
E/Home ( 4393): at
com.sharj.trafik.view.Home$3.onClick(Home.java:110)
E/Home ( 4393): at
android.view.View.performClick(View.java:2485)
E/Home ( 4393): at
android.view.View$PerformClick.run(View.java:9080)
E/Home ( 4393): at
android.os.Handler.handleCallback(Handler.java:587)
E/Home ( 4393): at
android.os.Handler.dispatchMessage(Handler.java:92)
E/Home ( 4393): at
android.os.Looper.loop(Looper.java:130)
E/Home ( 4393): at
android.app.ActivityThread.main(ActivityThread.java:3683)
E/Home ( 4393): at
java.lang.reflect.Method.invokeNative(Native
Method) E/Home ( 4393): at
java.lang.reflect.Method.invoke(Method.java:507)
E/Home ( 4393): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/Home ( 4393): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/Home ( 4393): at
dalvik.system.NativeStart.main(Native
Method) E/Home ( 4393): Caused by:
java.io.IOException: Received
authentication challenge is null
E/Home ( 4393): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153)
E/Home ( 4393): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:1095)
E/Home ( 4393): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1048)
E/Home ( 4393): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726)
E/Home ( 4393): at
org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:121)
E/Home ( 4393): at
twitter4j.internal.http.HttpResponseImpl.(HttpResponseImpl.java:35)
E/Home ( 4393): at
twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:168)
E/Home ( 4393): ... 18 more

It contains following links, but Google doesn't have much on this.

http://www.google.co.jp/search?q=6c607809

http://www.google.co.jp/search?q=0f1d8134

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

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

发布评论

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

评论(6

萌能量女王 2024-11-16 20:45:39

我也有同样的问题。事实证明,如果 oAuth 调用上的时间戳不正确,服务器将返回 401 状态错误,该错误在 Android 设备上会导致抛出“收到的身份验证质询为空”异常。所有出现此问题的设备都有不正确的时间,修复时间即可解决问题。

或许这也是你的问题?

I had the same problem. It turned out that if the time stamp on the oAuth call is incorrect, the server returns a 401 status error which on Android devices causes the "Received authentication challenge is null" exception to be thrown. All of the devices that were having this problem had incorrect times, and fixing the times fixed the problem.

Perhaps this is your issue as well?

善良天后 2024-11-16 20:45:39

我也有同样的问题。首先,我在执行 getOAuthRequestToken() 时得到它。我的消费者密钥和消费者秘密来自 .properties 文件,结果发现它们有一个尾随空格,因此被 Twitter 的 API 视为无效。

之后,我在执行 getOAuthAccessToken() 时也收到相同的 401。在这里,我没有正确地保存和重建 RequestToken 对象。

I also had the same problem. First I was getting it when doing getOAuthRequestToken(). My consumer key and consumer secret were coming from .properties file, and turned out they had a trailing space, so were seen as invalid by Twitter's API.

After that, I also was getting the same 401 when doing getOAuthAccessToken(). Here, I wasn't correctly persisting and re-constructing RequestToken object.

孤檠 2024-11-16 20:45:39

当我连续两次拨打以下电话时,就发生了这种情况:

 requestToken = twitter.getOAuthRequestToken();
    return requestToken.getAuthorizationURL();

This happened for me when I called the following twice in a row:

 requestToken = twitter.getOAuthRequestToken();
    return requestToken.getAuthorizationURL();
放我走吧 2024-11-16 20:45:39

已修复:即使在修复了日期和时间之后,我也遇到了此异常,但是当我在 logcat 中查看 twittherj 发送到服务器的参数时,时间戳仍然是错误的 - 所以我强制关闭了应用程序,然后异常消失了。

FIXED: I had this exception even after I fixed the date&time but when I looked in logcat at the params that twittherj sent to server the timestamp was still wrong - so I force-closed the app and after that exception was gone.

舂唻埖巳落 2024-11-16 20:45:39

我也偶然发现了这个问题。在另一个线程中检查我的解决方案 Android:Twitter4J 异常(已收到身份验证质询为空)

I too stumbled across this problem. Check my solution in another thread Android: Twitter4J Exception (Received Authentication Challenge Is Null)

少女情怀诗 2024-11-16 20:45:39

我遇到了同样的问题并通过使用异步任务修复了它
正如我在以下链接中回答的那样
Android Twitter 异常错误:(

I had same problem and fixed it by Using Asynchronous task
as I answered in the following link
Android Twitter exception error :(

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