2

这与使用 Facebook Android SDK 3.0 上传照片时出现的间歇性 SSL 错误类似,但该问题没有回复,我想在问题中提供更多详细信息。

我正在尝试使用以下代码将照片上传到用户的 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()IntentService.

4

1 回答 1

0

我找到了解决这个问题的方法,它涉及绕过 Facebook SDK 并自己进行 HTTP 调用。详情在这里:https ://stackoverflow.com/a/15260387/758458

于 2013-03-11T19:07:00.820 回答