How to publish image and URL on Facebook using latest facebook SDK for Android?

时光怂恿深爱的人放手 提交于 2019-12-25 14:12:01

问题


I want to create a Facebook dialog as shown in the last image of this link. But I am not able to see the default message and also not able to see the image. I wrote this code with help of this link.

Here is the code for the same:

public void postToWall(String message) {

    Bundle parameters = new Bundle();
    parameters.putString("method", "stream.publish");

    JSONObject attachment = new JSONObject();

    try {

        attachment.put("app_id", APP_ID);
        attachment.put("href", MY_URL);
        attachment.put("picture", MY_PICTURE_URL);
        attachment.put("name", NAME_FOR_URL);
        attachment.put("caption", CAPTION_FOR_URL);
        attachment.put("description", DESCRIPTION_FOR_URL);
        attachment.put("message", MESSAGE);

    } catch (JSONException e) {
        e.printStackTrace();
    }

    parameters.putString("attachment", attachment.toString());
    facebook.dialog(this, "stream.publish",parameters, new TestUiServerListener());


    }

What am I missing?


回答1:


Try this Snippet for Posting Image along with additional Details :

private void post_facebook() {
    Bundle parameters = new Bundle();
    parameters.putString("method", "stream.publish");

    JSONObject attachment = new JSONObject();

            // for adding image to Dialog       
    try {
        JSONObject media = new JSONObject();
        media.put("type", "image");
        media.put("src", "Any Image Link");
        media.put("href", "Any Image Link");
        attachment.put("media", new JSONArray().put(media));
    } catch (JSONException e1) {
    }

            // End if Image attachment

            // for adding Message with URL link
    try {
        attachment.put("message", "Messages");
        attachment.put("name", "Check out");
        attachment.put("href", "http://www.google.com");
    } catch (JSONException e) {
    }

    parameters.putString("attachment", attachment.toString());
    authenticatedFacebook.dialog(Settings_View.this, "stream.publish",parameters, new TestUiServerListener());
}


来源:https://stackoverflow.com/questions/8911470/how-to-publish-image-and-url-on-facebook-using-latest-facebook-sdk-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!