FB ui feed在墙上张贴后收到消息

时间:2013-11-14 11:03:47

标签: javascript jquery facebook facebook-graph-api

我正在使用此功能启动UI Feed,以便在我的网站上发布我网站上的内容。 :

 FB.ui({
      method: 'feed',
      name: myname,
      link: window.location.href,
      picture: mypic,
      caption: '',
      description: desc
    },function(response){}
  });

我需要在回调中执行回调,我可以在其中检索我在Facebook对话框中插入的消息,我正在搜索但没有找到获取它的方法,我还尝试将keydown事件委托给对话框的textarea,但它不起作用。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

为了从对话框中创建的帖子中提取数据,您可以从对话框提供的回调函数中检索post_id。在回调中,您将能够检查response对象。如果帖子成功创建,它将包含post_id

使用此post_id,您可以执行对API的额外调用,并将post_id`作为端点提供:

https://graph.facebook.com/POST_ID

或使用JavaScript SDK:

FB.api( '/POST_ID', function( response ) {
  console.log( response );
} );

看看第二次调用的响应对象,它看起来像这样:

{
  "id": "POST_ID", 
  "from": {
    "name": "Lix", 
    "id": "XXXYYY"
  }, 
  "message": "Checkout this awesome link!", 
  "picture": "https://fbexternal-a.akamaihd.net/...", 
  ...
}

如您所见,消息包含在响应中,因此要增强我之前的示例:

FB.api( '/POST_ID', function( response ) {
  if ( response ){
    console.log( response.message );
  }
} );

现在我们可以将所有内容与FB.ui调用结合起来:

 FB.ui({
      method: 'feed',
      ...
    },function( response ){
      if ( response && response.post_id ){
        FB.api( '/' + response.post_id, function( response ) {
          console.log( response );
        } );
      }
    }
  });
相关问题