【问题标题】:Graph Story Image Upload图表故事图片上传
【发布时间】:2013-07-01 14:14:05
【问题描述】:

我正在开发一个 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());

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

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

【问题讨论】:

    标签: android facebook facebook-opengraph


    【解决方案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));
    

    【讨论】:

    • 我设法通过添加“/me/stager_resources”请求调用解决了我的问题。现在我面临的问题是我必须放置“user_generated”,但似乎它应该以某种方式链接到“image”参数。我该怎么做?
    • 更新了答案以包含代码示例。请注意,由于我没有编译它,因此可能存在轻微的语法错误。
    • 如果我做params.putString("image",obj.toString())而不是将其设置为操作,它会起作用吗?
    • 非常感谢,它成功了。现在已经为此工作了大约 5 天。
    猜你喜欢
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2011-12-12
    • 2013-06-11
    • 2014-03-12
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多