Android 使用Facebook SDK上载照片时出错

Android 使用Facebook SDK上载照片时出错,android,facebook,android-facebook,Android,Facebook,Android Facebook,这是一个与类似的问题,但该问题没有回答,我想在问题中提供更多细节 我正在尝试使用以下代码将照片上载到用户的Facebook帐户: ArrayList<Request> requests = new ArrayList<Request>(); for (String id : ids) { Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); Bit

这是一个与类似的问题,但该问题没有回答,我想在问题中提供更多细节

我正在尝试使用以下代码将照片上载到用户的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());
    }
}
我确信的事情:

  • 我在请求中发送的位图有效
  • 我已通过活动会话正确登录Facebook
在大约15到20次的尝试中,我成功地两次实现了这一点(通过在我的浏览器中访问Facebook并在那里看到图像进行验证)


我认为这并不重要,但这发生在
IntentService

onHandleIntent()
方法中。我找到了一个解决这个问题的方法,绕过Facebook SDK,自己进行HTTP调用。这里的细节:

我也经历了同样的事情。看起来图像也没有为我上传,尽管请求花费了相当长的时间,好像上传成功一样。我很想知道问题出在哪里。我最终重写了我的服务,使用了不推荐的Facebook SDK调用:
new-Facebook(“appID”)。request(“me/photos”,params,“POST”)
虽然有效,但并不理想。但我不明白为什么它会起作用,因为据我所知,基本的POST调用是相同的。这可能与此有关吗
System.setProperty(“java.net.preferIPv6Address”,“false”)建议的修复程序解决问题了吗?AndroidHttpClient不支持写入OutputStream。我还在努力。尽管这可能会解决问题,但SDK还是坏了。我们应该注册一个bug,这样Facebook团队就可以修复它了!
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