Android Facebook Open Graph?

流过昼夜 提交于 2019-12-02 07:19:33

I use this code to publish on wall for multiple object properties.

     private void publishPhoto(String imageURL) {
    Log.d("FACEBOOK", "Post to Facebook!");

    try {

        JSONObject attachment = new JSONObject();
        attachment.put("message",text);
        attachment.put("name", "MyGreatAndroidAppTest");
        attachment.put("href", "http://stackoverflow.com/users/909317/sunny");
        attachment.put("description","Test Test TEst");

        JSONObject media = new JSONObject();
        media.put("type", "image");
        media.put("src",  imageURL);
        media.put("href",imageURL);
        attachment.put("media", new JSONArray().put(media));

        JSONObject properties = new JSONObject();

        JSONObject prop1 = new JSONObject();
        prop1.put("text", "Text or captionText to Post");
        prop1.put("href", imageURL);
        properties.put(text, prop1);

        // u can make any number of prop object and put on "properties" for    ex:    //prop2,prop3

        attachment.put("properties", properties);

        Log.d("FACEBOOK", attachment.toString());

        Bundle params = new Bundle();
        params.putString("attachment", attachment.toString());
        facebook.dialog(MyProjectActivity.this, "stream.publish", params, new DialogListener() {

            @Override
            public void onFacebookError(FacebookError e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(DialogError e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onComplete(Bundle values) {
                final String postId = values.getString("post_id");
                if (postId != null) {
                    Log.d("FACEBOOK", "Dialog Success! post_id=" + postId);
                    Toast.makeText(MyProjectActivity.this, "Successfully shared on Facebook!", Toast.LENGTH_LONG).show();

                } else {
                    Log.d("FACEBOOK", "No wall post made");
                }

            }

            @Override
            public void onCancel() {
                // TODO Auto-generated method stub

            }
        });      

    } catch (JSONException e) {
        Log.e("FACEBOOK", e.getLocalizedMessage(), e);
    }
}
Leonardo Sofia

To see a complete example look at the wishlist example.

A complete example for Android is included. The package includes the files to be uploaded on the server and a readme file that explain how to set up all the stuff on the open graph panel.

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