图形图像的故事上传 [英] Graph Story Image Upload

查看:187
本文介绍了图形图像的故事上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序,它可以让你发布一个故事,我希望用户上传照片。

I'm working on an Android app which lets you post a story and I want the user to upload a photo.

该应用程序具有publish_actions权限,它已user_generated,FB:explicitly_shared。

The app has the "publish_actions" permission and it has "user_generated", "fb:explicitly_shared".

我的code是以下

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();

当我检查测试帐户时间轴的故事被张贴,但没有图像。我想这个问题是在这条线:

When I check the test account timeline the story is posted, but there is no image. I suppose the problem is on this line:

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

我认为这个问题是无论哪种方式,关键是不是形象,或者不是你是怎么做到的。

I think the problem is either way the key is not "image" or that's not how you do it.

什么是做到这一点的正确方法?

What's the right way to do this?

推荐答案

从我的评论在您的其他问题:

From my comment in your other question:

您不能上传图片到你的我/:端点。你需要它的第一篇文章给我/ staging_resources。怎么看这个,对使用对象的API(特别是第3步图像上载)。

You can't upload an image to your me/: endpoint. You need to POST it to me/staging_resources first. See this how-to on using the Object API (specifically step 3 for image uploading).

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

要将图像添加到您的Open Graph的动作,做这样的事情:

To add the image to your open graph action, do something like:

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

这篇关于图形图像的故事上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆