Android and Facebook As an action with an Open Graph object

Facebook for mobile applications has been released as an action.

As the documentation says:

To publish a built-in Like action on an Open Graph object,
invoke the following HTTP POST request with a user’s access
token and the url of the Open Graph object.
This Open Graph object can be of any type.

curl -X POST \
    -F 'access_token=USER_ACCESS_TOKEN' \
    -F 'object=OG_OBJECT_URL' \
    https://graph.facebook.com/[User FB ID]/og.likes

Usually, to make a request, for example, for user information, I use this code:

Facebook facebook;
facebook = new Facebook(AppConfig.FACEBOOK_APP_ID);

if (facebook.isSessionValid())
{
    JSONObject obj = facebook.request("me");
    ...
}
else
{
    facebook.authorize(...)
    {
        @Override public void onComplete(Bundle values)
        {
            String token = facebook.getAccessToken();
            long expires = facebook.getAccessExpires();
            ...
        }
    }
}

My question is dead, but I can’t find the answer, how can I make the request “graph.facebook.com/[User FB ID] /og.likes” in the JAVA code, as soon as I get the user access token and expires?

+5
source share
1 answer

You would do something like the following:

1 / After initializing the facebook instance, you can declare the following:

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);

2 / Then, when you want to post this, you can use the following code:

Bundle params = new Bundle();
params.putString("object",OG_OBJECT_URL);

mAsyncRunner.request("me/og.likes", params, 
                    "POST", new BaseRequestListener() {
                       @Override
                       public void onComplete(final String response, final Object state) {
                           // handle success
                       }
                    });

3/ BaseRequestListener : https://github.com/fbsamples/android-social-cafe/blob/master/src/com/facebook/samples/socialcafe/BaseRequestListener.java

, Open Graph, , . : https://github.com/fbsamples/android-social-cafe

0

All Articles