你可以使用facebook sdk作为用户发表评论吗?

时间:2017-12-19 04:20:16

标签: javascript facebook facebook-graph-api facebook-javascript-sdk

这可能已被问到,但我刚刚搜索了几个小时。我试图评论我在Facebook登录时使用我的网络应用程序发布的帖子。我不想发表评论作为Web应用程序页面管理员。我希望在用户登录我的网站上的Facebook时发布评论,同时记住帖子ID。当我尝试发表评论时,我得到了这个

 Publishing comments through the API is only available for page access tokens

我正在使用这段代码

FB.api(response.data[0].id+'/comments', 'post',{message: "good work"},function(response){
                            console.log(response);
                          });

我开始认为不再可能了。我希望有人能给我一个具体的答案,谢谢你。

2 个答案:

答案 0 :(得分:2)

错误消息告诉您无法再评论“作为用户”。您只能使用页面标记进行评论,这意味着您只能评论“作为页面”。

更改日志:https://developers.facebook.com/docs/graph-api/changelog/version2.10#gapi-90-comments

  

POST和DELETE / {object-id} / comments - 此节点现在需要有效   页面访问令牌。

答案 1 :(得分:-1)

基本全页登录示例:



//<![CDATA[
/* external.js */
var doc, bod, I, fI, old = onload; // for use on other loads
onload = function(){
if(old)old(); // change old var name if using technique on other pages

doc = document; bod = doc.body;
I = function(id){
  return doc.getElementById(id);
}
fI = function(client_id, redirect_uri, onLogin, onLoginContext){
  var c = onLoginContext || this;
  FB.getLoginStatus(function(r){
    if(r.status === 'connected'){
      onLogin.call(c);
    }               
    else{
      location = 'https://www.facebook.com/dialog/oauth?client_id='+client_id+'&redirect_uri='+redirect_uri;
    }
  });
}
var out = I('out');
fI('571652776188445', 'https://phpglue.com/fakebook', function(){
  FB.api('708713672667337', 'post', {message:'Testing Facebook JavaScript SDK'}, function(r){
    out.innerHTML = r.message;
  });
}); // app I will never fully develop

}
//]]>
 
&#13;
/* external.css */
html,body{
  padding:0; margin:0;
}
body{
  background:#000; overflow-y:scroll;
}
.main{
  width:936px; background:#fff; padding:20px; margin:0 auto;
}
&#13;
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
  <head>
    <meta http-equiv='content-type' content='text/html;charset=utf-8' />
    <meta name='viewport' content='width=device-width' />
    <title>Facebook Basic Full Page Login</title>
    <link type='text/css' rel='stylesheet' href='external.css' />
    <script type='text/javascript' src='https://connect.facebook.net/en_US/sdk.js'></script>
    <script type='text/javascript' src='external.js'></script>
  </head>
<body>
  <div class='main'>
    <div id='out'>You have to test this from Your Facebook App</div>
  </div>
</body>
</html>
&#13;
&#13;
&#13;