Android和Facebook喜欢使用Open Graph对象的动作

时间:2012-07-09 22:11:51

标签: android facebook-like

Facebook for action已针对移动应用发布。

正如文件所说:

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

通常,为了提出例如用户信息的请求,我使用这种代码:

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();
            ...
        }
    }
}

我的问题很简单,但我找不到答案,如何检索用户,如何在JAVA代码中生成“graph.facebook.com/ [User FB ID] /og.likes”请求访问令牌并过期?

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

1 /初始化facebook实例后,您可以声明以下内容:

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);

2 /然后当您想要发布时,您可以使用以下代码:

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