Can't post image to Twitter. Received authentication challenge is null

試著忘記壹切 提交于 2019-12-23 03:13:39

问题


After the login flow, I store access token and accesss token secret in prefs. Now I want to post image to Twitter using TwitPic.

Updated: I tried to set date&time on device to automatic. The callback URL in my Twitter app exists. It still shows error.

My code

public static boolean tweetMessageAndPhoto(final String message, final String photoPath) {
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthAccessToken(getAccessTokenStr());
    cb.setOAuthAccessTokenSecret(getAccessTokenSecretStr());
    cb.setOAuthConsumerKey(Constant.CONSUMER_KEY);
    cb.setOAuthConsumerSecret(Constant.ACCESS_TOKEN_SECRET);
    cb.setMediaProviderAPIKey(Constant.MEDIA_KEY);              
    final Configuration conf = cb.build();

    final ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);

    try {
        final String uri = upload.upload(new File(photoPath), message);
        System.out.println("================URI: " + uri);
        return true;
    } catch (final TwitterException e) {
        e.printStackTrace();
        ShowLog.showLogError(TAG, "Could not tweet. Please try again.");
    }
    return false;
}

I get this error:

W/System.err(14566): Received authentication challenge is nullRelevant discussions can be on the Internet at:
W/System.err(14566):    http://www.google.co.jp/search?q=ea09dc6d or
W/System.err(14566):    http://www.google.co.jp/search?q=049b821e
W/System.err(14566): TwitterException{exceptionCode=[ea09dc6d-049b821e 0237e8c8-8ed4bd69], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.3}
W/System.err(14566):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:204)
W/System.err(14566):    at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
W/System.err(14566):    at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:114)
W/System.err(14566):    at twitter4j.media.AbstractImageUploadImpl.upload(AbstractImageUploadImpl.java:111)
W/System.err(14566):    at twitter4j.media.AbstractImageUploadImpl.upload(AbstractImageUploadImpl.java:80)
W/System.err(14566):    at app.jp.cropnet.twitter.TwitterHelper.tweetMessageAndPhoto(TwitterHelper.java:121)
W/System.err(14566):    at app.jp.cropnet.twitter.TwitterDemoActivity.tweetMessageAndPhoto(TwitterDemoActivity.java:81)
W/System.err(14566):    at app.jp.cropnet.twitter.TwitterDemoActivity.access$1(TwitterDemoActivity.java:78)
W/System.err(14566):    at app.jp.cropnet.twitter.TwitterDemoActivity$2.onClick(TwitterDemoActivity.java:40)
W/System.err(14566):    at android.view.View.performClick(View.java:2461)
W/System.err(14566):    at android.view.View$PerformClick.run(View.java:8890)
W/System.err(14566):    at android.os.Handler.handleCallback(Handler.java:587)
W/System.err(14566):    at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(14566):    at android.os.Looper.loop(Looper.java:123)
W/System.err(14566):    at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err(14566):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(14566):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(14566):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
W/System.err(14566):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
W/System.err(14566):    at dalvik.system.NativeStart.main(Native Method)
W/System.err(14566): Caused by: java.io.IOException: Received authentication challenge is null
W/System.err(14566):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequestInternal(HttpURLConnectionImpl.java:1694)
W/System.err(14566):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.doRequest(HttpURLConnectionImpl.java:1649)
W/System.err(14566):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:1374)
W/System.err(14566):    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:117)
W/System.err(14566):    at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:35)
W/System.err(14566):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:168)
W/System.err(14566):    ... 19 more

回答1:


If you are using simulator, this should work fine, and if you are getting error only on real device, please check that the sim card you inserted in the phone has automatic time update feature enable. I once got into the problem, changing sim card from other network solved my problem.



来源:https://stackoverflow.com/questions/11775975/cant-post-image-to-twitter-received-authentication-challenge-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!