2013-03-21 61 views
0

的时候,这里是我的代码意外的标记功能处理Facebook的响应

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打印 是否有另一种方式来处理响应?

+2

这是一个JavaScript语法错误,无关与Facebook的代码不会运行。 – Esailija 2013-03-21 21:06:02

+0

什么语法错误呢?正如你在评论中指出的那样,我有所有正确的方括号 – user2185501 2013-03-21 21:08:09

回答

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

    } 
}) 
+0

错过了commo – user2185501 2013-03-21 21:47:40