'赞'在Android中通过Graph API链接

时间:2011-08-09 11:06:15

标签: facebook facebook-graph-api

有没有人知道是否可以通过Graph API“喜欢”一个非Facebook链接?

例如,我想要链接

https://stackoverflow.com/

通过我的应用。

我是否必须发布此链接并在之后“赞”我的帖子,还是有直接的方式?

我很感谢任何有帮助的答案! :)

谢谢!

2 个答案:

答案 0 :(得分:0)

图表api允许您使用:

来表示图形对象(请参阅Graph API Docs / Publishing
https://graph.facebook.com/OBJECT_ID/likes

然而,图形对象必须具有现有的 like 连接 - 并且目前无法通过图形api创建这样的连接。

但是如果已经存在类似连接,则可以使用FQL获取页面图形对象id:

SELECT id FROM object_url WHERE url='http://youtargeturl.lnk'

答案 1 :(得分:0)

现在在sdk3中你使用open graph api

private void likeStory() {
    Session session = Session.getActiveSession();

    if (session != null){

        // Check for publish permissions    

        Request.Callback callback= new Request.Callback() {
            public void onCompleted(Response response) {
                if (response!=null){
                    Log.d("Lavoro", "response"+response.toString());

                    JSONObject graphResponse=null;


                    if (response.getGraphObject()!=null){
                        graphResponse = response.getGraphObject()
                            .getInnerJSONObject();
                        try {
                            postId = graphResponse.getString("id");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }                       


                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Toast.makeText(activity, error.getErrorMessage()+error.getErrorCode(), Toast.LENGTH_SHORT).show();
                        buttonFacebookLike.setVisibility(View.INVISIBLE);
                    } else {
                        Toast.makeText(activity, postId, Toast.LENGTH_LONG).show();
                        buttonFacebookLike.setVisibility(View.VISIBLE);
                        updateLike();
                    }
                }
            }
        };

        Log.d("Lavoro", "postId like"+postId);
        Bundle postParams = new Bundle();
        postParams.putString("object", "URL TO LIKE");

         Request request = new Request(session, "me/og.likes", postParams, HttpMethod.POST, callback);
        Log.d("Lavoro", "request"+request.toString());

       // Request request = new Request(session, postId+"/comments", postParams, 
       //         HttpMethod.POST, callback);
        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
    }
}