图形故事图像上传

时间:2013-07-01 14:14:06

标签: android facebook opengraph

我正在开发一款Android应用,可让您发布故事,我希望用户上传照片。

该应用具有“publish_actions”权限,并且具有“user_generated”,“fb:explicit_shared”。

我的代码如下

ByteArrayOutputStream stream = new ByteArrayOutputStream();
    if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)) {
        Log.i(TAG,"Bitmap compressed into stream successfully.");
    }

    postParams.putByteArray("image", stream.toByteArray());

    postParams.putString("user_generated", "true");
    postParams.putString(OBJECT,URL);
    postParams.putString("fb:explicitly_shared", "true");

Log.i(TAG,"Executing facebook graph story request...");

    Request request = new Request(session, "me/<appnamespace>:<action>", postParams, HttpMethod.POST, callback);
    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();

当我查看测试帐户时间线时,会发布故事,但没有图像。我想问题出在这一行:

postParams.putByteArray("image", stream.toByteArray());

我认为问题在于关键不是“形象”,或者不是你的工作方式。

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

来自我对你问题的评论:

您无法将图像上传到me /:端点。您需要先将它发送给我/ staging_resources。请参阅此使用Object API的方法(特别是步骤3进行图像上传)。

https://developers.facebook.com/docs/howtos/androidsdk/3.0/share-using-object-api/

要将图像添加到打开的图表操作中,请执行以下操作:

JSONObject obj = new JSONObject();
obj.put("url", <your staging uri here>);
obj.put("user_generated", true);
myAction.setImage(Arrays.asList(obj));