Sanju Sony Kurian
Sanju Sony Kurian

Reputation: 194

Android: OpenGraph Stories sharing in Facebook with SDK 4.0

I am trying to implement achievements for sharing to facebook when the player unlocks a badge. Have made an object using the object browser in facebook developer console. I made Action-types and object-types and made a custom story. Now i am stuck trying to share the story to facebook. The documentation given by facebook is inadequate. Even the sample code given by facebook uses v3.x

Sample code given by facebook is given below. Couldnt find any good documentation.

Code for Object

Bundle params = new Bundle();
Request request = new Request(
    Session.getActiveSession(),
    "me/objects/enguru_app:badge",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

Code for Action

Bundle params = new Bundle();
params.putString("badge", "http://samples.ogp.me/1114467558579559");
Request request = new Request(
    Session.getActiveSession(),
    "me/enguru_app:unlocked",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

Upvotes: 2

Views: 2822

Answers (3)

YTerle
YTerle

Reputation: 2696

If you are looking for how to share without using ShareDialog:

ShareApi shareApi = new ShareApi(content);
shareApi.share(new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
});

Also you probably want to check shareApi.canShare()

Upvotes: 0

Sanju Sony Kurian
Sanju Sony Kurian

Reputation: 194

At Last figured out my own issue.

Here is the solution:

ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "enguru_app:badge")
            .putString("og:title", "Unlocked Newbie Badge")
            .putString("og:url","xxxx")
            .putString("og:image","xxx")
            .putString("game:points", "10")
            .putString("fb:app_id", "xxx")
            .putString("og:description",
                    "We are rocking. Come and Play with us").build();
    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("enguru_app:unlocked")
            .putObject("badge", object).build();
    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("badge").setAction(action)
            .build();

    ShareDialog.show(Profile.this, content);

I hope this will help someone who is going through the same issue.

Upvotes: 6

Gokhan Caglar
Gokhan Caglar

Reputation: 1137

See this page: https://developers.facebook.com/docs/sharing/android Specifically ShareOpenGraphObject and ShareOpenGraphAction.

Also you can debug through Scrumptious: https://github.com/facebook/facebook-android-sdk/blob/master/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java#L365

Upvotes: 0

Related Questions