编程语言
首页 > 编程语言> > Java-Facebook API / Android:墙上发布带有图像附件的发布不起作用

Java-Facebook API / Android:墙上发布带有图像附件的发布不起作用

作者:互联网

我有以下代码.

它可以工作并发布消息部分,但是附件部分不起作用.
我怀疑这与将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正文中启用.

另外,“连接”方式是一种古老的方式,不再使用.
它看起来应该像这样:

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上传图像的官方参考:Uploading Photos to the Graph API via a URL.
可以在User object文档中找到用于发布到Feed的参数.

标签:java,facebook,facebook-graph-api,facebook-android-sdk
来源: https://codeday.me/bug/20191013/1910624.html