Skip to content Skip to sidebar Skip to footer

Android Facebook Open Graph?

I am curious if I can get some help with Open Graph since I can't seem to make any sense out of the Facebook API that I have read. Right now I have setup my Open Graph Application

Solution 1:

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

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

    try {

        JSONObject attachment = newJSONObject();
        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 = newJSONObject();
        media.put("type", "image");
        media.put("src",  imageURL);
        media.put("href",imageURL);
        attachment.put("media", newJSONArray().put(media));

        JSONObject properties = newJSONObject();

        JSONObject prop1 = newJSONObject();
        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 = newBundle();
        params.putString("attachment", attachment.toString());
        facebook.dialog(MyProjectActivity.this, "stream.publish", params, newDialogListener() {

            @OverridepublicvoidonFacebookError(FacebookError e) {
                // TODO Auto-generated method stub

            }

            @OverridepublicvoidonError(DialogError e) {
                // TODO Auto-generated method stub

            }

            @OverridepublicvoidonComplete(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");
                }

            }

            @OverridepublicvoidonCancel() {
                // TODO Auto-generated method stub

            }
        });      

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

Solution 2:

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.

Post a Comment for "Android Facebook Open Graph?"