Facebook API / Android:Wall Post发布与图像附件不工作 [英] Facebook API / Android : Wall Post publish with image attachment not working

查看:131
本文介绍了Facebook API / Android:Wall Post发布与图像附件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。

它工作并发布消息部分,但附件部分不工作。
我怀疑这是将JSON作为一个字符串传递。

It works and posts the message-part but the attachment part does'nt work. I suspect it has to do with passing a JSON as a string.

Facebook返回{id:23522646737635675 。所以它不是一个错误。

Facebook returns "{"id":"23522646737635675"}. So its not an error.

        Bundle params = new Bundle();

        params.putString("message", message);

        JSONObject attachment = new JSONObject();

        attachment.put("href", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));
        attachment.put("name", "Cricket Fantasy");
        attachment.put("caption", "New team");
        attachment.put("description","Description about Application");

        JSONObject media = new JSONObject();

        media.put("type", "image");
        media.put("src", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));
        media.put("href", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));
        attachment.put("media", media);

        params.putString("attachement", attachment.toString());

        String response = mFacebook.request("me/feed", params, "POST");


推荐答案

您不能将json编码数据发送到Facebook,这样不行。
每个参数都应该在POST正文中。

You can't send json encoded data to facebook, doesn't work that way. Each parameter should be on it's on in the POST body.

此外,附件方式是旧的,不再使用。
应该看起来像:

In addition, the "attachment" way is an old one and not used anymore. It should look something like:

Bundle params = new Bundle();

params.putString("message", message);
params.put("name", "Cricket Fantasy");
params.put("caption", "New team");
params.put("description","Description about Application");
params.put("url", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));

String response = mFacebook.request("me/feed", params, "POST");

可以在这里找到使用网址上传图片的官方参考:通过URL将照片上传到Graph API
可以在用户对象中找到发布到Feed的参数 doc。

An official reference for uploading images using urls can be found here: Uploading Photos to the Graph API via a URL. The parameters for posting to a feed can be found in the User object doc.

这篇关于Facebook API / Android:Wall Post发布与图像附件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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