微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Facebook Android SDK 3.0上传照片时出现间歇性SSL错误

我正在使用Facebook Android SDK 3.0将照片上传到我的相册.一切正常,但有时第一次上传失败,出现了一些意想不到的SSL错误.

请参阅Request.java中的函数tohttpconnection.

try {
        connection = createConnection(url);

        serializetoUrlConnection(requests, connection);
    } catch (IOException e) {
        // THIS IS WHERE THE ERROR ORIGINATES FROM!
        throw new FacebookException("Could not construct request body", e);
    } catch (JSONException e) {
        throw new FacebookException("Could not construct request body", e);
    }

在Eclipse中悬停e会显示以下信息:

javax.net.ssl.SSLException:写入错误:ssl = 0x4f033008:系统调用间的I / O错误,管道损坏
javax.net.ssl.SSLException:写入错误:ssl = 0x4f033008:系统调用间的I / O错误,管道损坏
写入错误:ssl = 0x4f033008:系统调用间的I / O错误,管道损坏
[1277468208,0,1279934152,48,1280860304,26,1280860480,58,1280859576,11,1280859696,4,1277492792,1,1280859640,7,1280233152,169,1280233264,36,1280230744,6,1280236632,0,1280236576 ,0,1280238568,6,1280238512,2,1278731744,21,1279835640,23,1278097880,2,1279841920,28,1279843376,2,1277300032,6]
空值

这是SDK中的错误吗?有没有人遇到过这个?更重要的是,我该如何解决

解决方法:

我几乎准备好接受我之前(删除)的答案,直到我看到这篇文章http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

我决定试一试,它似乎工作!这是我的代码

for (Bitmap b : bitmaps) {
    // id is just a string
    String response = executeUpload(b, id);

    // do something with the response
}

private String executeUpload(Bitmap b, String id) throws MalformedURLException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    b.compress(CompressFormat.PNG, 100, baos);
    byte[] data = baos.toByteArray();

    HttpPost postRequest = new HttpPost("https://graph.facebook.com/me/photos");
    HttpParams params = new BasicHttpParams();
    httpconnectionParams.setConnectionTimeout(params, 3000);
    HttpClient httpClient = new DefaultHttpClient();
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(2, true));

    ByteArrayBody bab = new ByteArrayBody(data, id + ".png");
    multipartentity reqEntity = new multipartentity(HttpMultipartMode.broWSER_COMPATIBLE);
    reqEntity.addPart("access_token", new StringBody(activeFacebookAccesstoken));
    reqEntity.addPart("message", new StringBody(""));
    reqEntity.addPart("picture", bab);
    postRequest.setEntity(reqEntity);
    HttpResponse response = httpClient.execute(postRequest);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String s;
    StringBuilder builder = new StringBuilder();
    while ((s = reader.readLine()) != null) {
        builder = builder.append(s);
    }

    return builder.toString();
}

如上面的链接所述,您必须安装最新的HttpClient(位于http://hc.apache.org/downloads.cgi).

一个需要注意的重要事项是,Facebook支持任一维度的最大图像大小为720像素.在我的代码中,我在进行上传之前将位图缩放到该大小限制内,这极大地提高了性能.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐