gpt4 book ai didi

java - Facebook API/Android : Wall Post publish with image attachment not working

转载 作者:行者123 更新时间:2023-11-30 04:48:01 25 4
gpt4 key购买 nike

我有以下代码。

它可以工作并发布消息部分,但附件部分不起作用。我怀疑这与将 JSON 作为字符串传递有关。

Facebook 返回 "{"id":"23522646737635675"}。因此这不是错误。

        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 正文中。

另外,“attachment”方式是一种旧的方式,不再使用了。它应该看起来像:

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

可以在此处找到使用网址上传图像的官方引用:Uploading Photos to the Graph API via a URL 。用于发布到提要的参数可以在 User object 中找到。文档。

关于java - Facebook API/Android : Wall Post publish with image attachment not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10510071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com