0

我正在开发一个 Android 应用程序,它可以让你发布一个故事,我希望用户上传一张照片。

该应用程序具有“publish_actions”权限,并且具有“user_generated”、“fb:explicitly_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());

我认为问题在于关键不是“图像”,或者不是你这样做的方式。

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

4

1 回答 1

1

根据我对您其他问题的评论:

您无法将图像上传到您的 me/: 端点。您需要先将其发布给我/staging_resources。请参阅此关于使用对象 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));
于 2013-07-01T18:23:24.273 回答