1

在登录流程之后,我将访问令牌和访问令牌秘密存储在 prefs 中。现在我想使用 TwitPic 将图像发布到 Twitter。

更新:我尝试将设备上的日期和时间设置为自动。我的 Twitter 应用程序中的回调 URL 存在。它仍然显示错误。

我的代码

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;
}

我收到此错误:

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
4

1 回答 1

3

如果您使用的是模拟器,这应该可以正常工作,如果您仅在真机上出现错误,请检查您插入手机的 sim 卡是否启用了自动时间更新功能。我曾经遇到过这个问题,从其他网络更换SIM卡解决了我的问题。

于 2012-08-02T11:08:46.943 回答