本文介绍了Twitter4J +安卓:认证挑战是空异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Twitter4J库OAuth认证,但我得到验证挑战是空例外它打开了微博登录页面之前。

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

下面是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.
    }

例外:

E /家(4393):收到  认证的挑战是空  E /家(4393):收到  认证的挑战是  nullRelevant讨论可以对  互联网在:E /家(4393):     http://www.google.co.jp/search?q=6c607809   或E /家庭(4393):     http://www.google.co.jp/search?q=0f1d8134   E /家(4393):  TwitterException {例外code = [6c607809-0f1d8134  cab4c0ac-d492a113],状态code = -1,  retryAfter = 0,rateLimitStatus =零,  版本= 2,2,2} E /家(4393):在  twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:204)  E /家(4393):在  twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)  E /家(4393):在  twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)  E /家(4393):在  twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:108)  E /家(4393):在  twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:271)  E /家(4393):在  com.sharj.trafik.view.Home.askOAuth(Home.java:157)  E /家(4393):在  com.sharj.trafik.view.Home.access $ 0(Home.java:143)  E /家(4393):在  com.sharj.trafik.view.Home $ 3.onClick(Home.java:110)  E /家(4393):在  android.view.View.performClick(View.java:2485)  E /家(4393):在  android.view.View $ PerformClick.run(View.java:9080)  E /家(4393):在  android.os.Handler.handleCallback(Handler.java:587)  E /家(4393):在  android.os.Handler.dispatchMessage(Handler.java:92)  E /家(4393):在  android.os.Looper.loop(Looper.java:130)  E /家(4393):在  android.app.ActivityThread.main(ActivityThread.java:3683)  E /家(4393):在  java.lang.reflect.Method.invokeNative(母语  法)E /家(4393):在  java.lang.reflect.Method.invoke(Method.java:507)  E /家(4393):在  com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)  E /家(4393):在  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)  E /家(4393):在  dalvik.system.NativeStart.main(母语  法)E /家(4393):产生的原因:  java.io.IOException异常:收到  认证的挑战是空  E /家(4393):在  org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processAuthHeader(HttpURLConnectionImpl.java:1153)  E /家(4393):在  org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:1095)  E /家(4393):在  org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1048)  E /家(4393):在  org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponse$c$c(HttpURLConnectionImpl.java:726)  E /家(4393):在  org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponse$c$c(HttpsURLConnectionImpl.java:121)  E /家(4393):在  twitter4j.internal.http.Htt presponseImpl(Htt的presponseImpl.java:35)。  E /家(4393):在  twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:168)  E /家(4393):18 ...更多

它包含以下链接,但谷歌并没有太多这一点。

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

推荐答案

我有同样的问题。原来,如果对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?

这篇关于Twitter4J +安卓:认证挑战是空异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:04