在Android上使用twitter4j客户端twit multiple picss

时间:2012-11-01 10:49:11

标签: android twitter twitter4j

我可以使用twitter4j lib为Android安装单张图片,但无法一次拍摄多张照片。这是我的代码,它适用于上传单张图片但显示多次上传的错误 -

11-01 16:23:41.250: W/System.err(12682): upload.twitter.comRelevant discussions can be     on the Internet at:
11-01 16:23:41.250: W/System.err(12682):    http://www.google.co.jp/search?q=b2b52c28 or
11-01 16:23:41.250: W/System.err(12682):    http://www.google.co.jp/search?q=19d05107
11-01 16:23:41.250: W/System.err(12682): TwitterException{exceptionCode=[b2b52c28-19d05107 b2b52c28-19d050b8], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.6-SNAPSHOT(build: 2a63ef13662e7cd135321926d315f91681d90ced)}
11-01 16:23:41.250: W/System.err(12682):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:200)
 11-01 16:23:41.250: W/System.err(12682):   at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
 11-01 16:23:41.250: W/System.err(12682):   at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
 11-01 16:23:41.250: W/System.err(12682):   at twitter4j.TwitterImpl.post(TwitterImpl.java:1762)
11-01 16:23:41.250: W/System.err(12682):    at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:412)
 11-01 16:23:41.250: W/System.err(12682):   at com.app.cakemaker2.TwitterWebViewActivity.loginAuthorisedUser(TwitterWebViewActivity.java:118)
 11-01 16:23:41.250: W/System.err(12682):   at com.app.cakemaker2.TwitterWebViewActivity.twt_works(TwitterWebViewActivity.java:80)
11-01 16:23:41.250: W/System.err(12682):    at com.app.cakemaker2.TwitterWebViewActivity.onCreate(TwitterWebViewActivity.java:73)
 11-01 16:23:41.250: W/System.err(12682):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 11-01 16:23:41.250: W/System.err(12682):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
 11-01 16:23:41.250: W/System.err(12682):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-01 16:23:41.250: W/System.err(12682):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 11-01 16:23:41.250: W/System.err(12682):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
 11-01 16:23:41.250: W/System.err(12682):   at android.os.Handler.dispatchMessage(Handler.java:99)
 11-01 16:23:41.250: W/System.err(12682):   at android.os.Looper.loop(Looper.java:130)
 11-01 16:23:41.250: W/System.err(12682):   at android.app.ActivityThread.main(ActivityThread.java:3691)
 11-01 16:23:41.250: W/System.err(12682):   at java.lang.reflect.Method.invokeNative(Native Method)
11-01 16:23:41.250: W/System.err(12682):    at java.lang.reflect.Method.invoke(Method.java:507)
11-01 16:23:41.250: W/System.err(12682):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
 11-01 16:23:41.250: W/System.err(12682):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
 11-01 16:23:41.250: W/System.err(12682):   at dalvik.system.NativeStart.main(Native Method)
 11-01 16:23:41.250: W/System.err(12682): Caused by: java.net.UnknownHostException: upload.twitter.com
  11-01 16:23:41.260: W/System.err(12682):  at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
 11-01 16:23:41.260: W/System.err(12682):   at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
11-01 16:23:41.260: W/System.err(12682):    at java.net.InetAddress.getAllByName(InetAddress.java:256)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
 11-01 16:23:41.260: W/System.err(12682):   at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
 11-01 16:23:41.260: W/System.err(12682):   at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
11-01 16:23:41.260: W/System.err(12682):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:614)
11-01 16:23:41.260: W/System.err(12682):    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:121)
11-01 16:23:41.260: W/System.err(12682):    ... 20 more

我的代码

/**
 * here is uploading works
 */
private void loginAuthorisedUser() {
    count = 0;

    for (i = 0; i < images_to_handle.size(); i++) {

        String token = mPrefs.getString(PREF_ACCESS_TOKEN, null);
        String secret = mPrefs.getString(PREF_ACCESS_TOKEN_SECRET, null);

        AccessToken at = new AccessToken(token, secret);

        mTwitter.setOAuthAccessToken(at);

        StatusUpdate status = new StatusUpdate(""+getResources().getString(R.string.mail_subject));
        String FILENAME = "cake buffet" + count;


        Bitmap bitmap = BitmapFactory.decodeFile(db_cake.fetchImagePath(images_to_handle.get(i)));
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
        byte[] imageInByte = stream.toByteArray();

        ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);

        status.setMedia(FILENAME, bis);

        try {

            mTwitter.updateStatus(status);
            Toast.makeText(this, "Tweet Successful!", Toast.LENGTH_SHORT)
                    .show();

            count++;

            Log.i("count", ""+count);

        } 
        catch (TwitterException e) {
            e.printStackTrace();
            Toast.makeText(this, "oh no!! twit error" + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();

        }
    }

}

好的......知道问题是什么......

0 个答案:

没有答案