处理Facebook响应时的意外令牌功能

时间:2013-03-21 21:03:51

标签: php javascript facebook-graph-api

这是我的代码

    echo '<script type="text/javascript"> 
     FB.init({
          appId   : "myappid",
          channelUrl : "//www.mysite/channel.html",
          status  : true, // check login status
          cookie  : true, // enable cookies to allow the server to access the session
          xfbml   : true // parse XFBML
        });
    FB.getLoginStatus(function(response) {
    if (response.status === "connected") {

    FB.api(
  "me/bookvote:download",
  "post",
  {
    book: "http://samples.ogp.me/199815506812566",
    fb:explicitly_shared = "true"
  }

 function(response) {
  if (!response || response.error) {
     alert("Error occured" + response.error);
   } else {
    alert("Post ID: " + response.id);
    }
    }
 )





   // else {
   //do nothing since user did not authorize
  // alert("I am an alert box!");

    // }
    }
    }
    )

    </script>';

当我添加

时,我在控制台中获得的错误是意外的令牌功能
 function(response) {
  if (!response || response.error) {
     alert("Error occured" + response.error);
   } else {
    alert("Post ID: " + response.id);
    }
    }
 )

这是facebook在这里https://developers.facebook.com/docs/reference/javascript/FB.api/所证明的, 帖子没有发给开发人员faecbook墙,所以我需要处理响应,看看Facebook正在打印什么错误消息 还有另一种处理响应的方法吗?

1 个答案:

答案 0 :(得分:0)

有一些缩进:

FB.init({
    appId: "myappid",
    channelUrl: "//www.mysite/channel.html",
    status: true, // check login status
    cookie: true, // enable cookies to allow the server to access the session
    xfbml: true // parse XFBML
});
FB.getLoginStatus(function (response) {
    if (response.status === "connected") {
        FB.api("me/bookvote:download", "post", {
            book: "http://samples.ogp.me/199815506812566",
            fb: explicitly_shared = "true" //? Is syntactically valid but creates a global
        } //Missing a , here?

        function (response) {
            if (!response || response.error) {
                alert("Error occured" + response.error);
            } else {
                alert("Post ID: " + response.id);
            }
        })

    }
})