Facebook API / Android:Wall Post发布图片附件无效

时间:2012-05-09 04:56:46

标签: java facebook facebook-graph-api facebook-android-sdk

我有以下代码。

它工作并发布消息部分但附件部分不起作用。 我怀疑它与将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");

2 个答案:

答案 0 :(得分:2)

你不能将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");

使用网址上传图片的官方参考资料可在此处找到:Uploading Photos to the Graph API via a URL。 可以在User object doc。

中找到发布到Feed的参数

答案 1 :(得分:0)

Bundle params = new Bundle();
                   // params.putString("multipart/form-data", imgurl);
                    params.putByteArray("multipart/form-data",byteArray);

                    params.putString("caption", txtcaption.getText().toString());
                    /* make the API call */
                    new GraphRequest(
                            AccessToken.getCurrentAccessToken(),
                            "/me/photos",
                            params,
                            HttpMethod.POST,
                            new GraphRequest.Callback() {
                                public void onCompleted(GraphResponse response) {
                                    /* handle the result */
                                    Log.e("responseImagedata---", response.toString());

                                }
                            }
                    ).executeAsync();