使用Facebook SDK上传照片时出错

时间:2013-02-28 19:34:12

标签: android facebook android-facebook

这是与Intermittent SSL error when uploading photos using Facebook Android SDK 3.0类似的问题,但该问题没有回复,我想在问题中提供更多细节。

我正在尝试使用以下代码将照片上传到用户的Facebook帐户:

ArrayList<Request> requests = new ArrayList<Request>();
for (String id : ids) {
    Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
    Bitmap b;
    try {
        b = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
    } catch (FileNotFoundException e) {
        Log.e(LOG_TAG, "Error uploading photo to facebook", e);
        return;
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error uploading photo to facebook", e);
        return;
    }
    if (b != null) {
        requests.add(Request.newUploadPhotoRequest(FacebookLoginHelper.getInstance().getActiveSession(), b,
                null));
    }
}
List<Response> responses = Request.executeBatchAndWait(requests);
for (Response response : responses) {
    if (response.getError() == null) {
        Log.w(LOG_TAG, "Successfully uploaded image");
    } else {
        Log.w(LOG_TAG, "Error uploading image: " + response.getError().getErrorMessage());
    }
}

我收到此错误:

02-28 11:26:52.936: W/System.err(5848): javax.net.ssl.SSLException: Write error:        ssl=0x72be0428: I/O error during system call, Broken pipe
02-28 11:26:52.936: W/System.err(5848):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
02-28 11:26:52.936: W/System.err(5848):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:706)
02-28 11:26:52.936: W/System.err(5848):     at libcore.net.http.ChunkedOutputStream.writeHex(ChunkedOutputStream.java:102)
02-28 11:26:52.936: W/System.err(5848):     at libcore.net.http.ChunkedOutputStream.writeBufferedChunkToSocket(ChunkedOutputStream.java:128)
02-28 11:26:52.946: W/System.err(5848):     at libcore.net.http.ChunkedOutputStream.write(ChunkedOutputStream.java:77)
02-28 11:26:52.946: W/System.err(5848):     at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
02-28 11:26:52.946: W/System.err(5848):     at java.io.BufferedOutputStream.write(BufferedOutputStream.java:139)
02-28 11:26:52.946: W/System.err(5848):     at android.graphics.Bitmap.nativeCompress(Native Method)
02-28 11:26:52.946: W/System.err(5848):     at android.graphics.Bitmap.compress(Bitmap.java:875)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request$Serializer.writeBitmap(Request.java:1688)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request$Serializer.writeObject(Request.java:1666)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request.serializeAttachments(Request.java:1569)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request.serializeToUrlConnection(Request.java:1467)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request.toHttpConnection(Request.java:933)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request.executeBatchAndWait(Request.java:1027)
02-28 11:26:52.946: W/System.err(5848):     at com.facebook.Request.executeBatchAndWait(Request.java:1003)
02-28 11:26:52.946: W/System.err(5848):     at com.mycompany.mypackage.services.FacebookPhotoUploadService.onHandleIntent(FacebookPhotoUploadService.java:50)
02-28 11:26:52.946: W/System.err(5848):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
02-28 11:26:52.946: W/System.err(5848):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 11:26:52.946: W/System.err(5848):     at android.os.Looper.loop(Looper.java:137)
02-28 11:26:52.946: W/System.err(5848):     at android.os.HandlerThread.run(HandlerThread.java:60)
02-28 11:26:52.946: D/skia(5848): ------- write threw an exception
02-28 11:26:52.946: W/com.mycompany.mypackage.services.FacebookPhotoUploadService(5848): Error uploading image: com.facebook.FacebookException: could not construct request body

我确定的事情:

  • 我在请求中发送的位图有效
  • 我已通过有效会话正确登录Facebook

我能够在大约15或20次尝试中成功完成两次(通过在浏览器中访问Facebook并在那里查看图像进行验证)。

我认为这不重要,但这种情况发生在onHandleIntent()的{​​{1}}方法中。

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法,包括绕过Facebook SDK并自行进行HTTP调用。详情请见https://stackoverflow.com/a/15260387/758458