我想使用 JS SDK 在我的画布页面中获取发件人的 ID。
我已经编写了这段代码,但它不起作用:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en" lang="en">
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
console.log("one");
window.fbAsyncInit = function() {
FB.init({
appId : 'myAppId', // App ID
status: true,
cookie: true,
xfbml: true,
oauth: true});
console.log("two");
FB.api("/me/apprequests", function(response) {
console.log("1");
if (response.data && response.data.length > 0) {
console.log("2");
for (var i = 0; i < response.data.length; i++) {
console.log("3");
if (response.data[i].from) {
console.log("Sender: " + response.data[i].from);
}
else {
console.log("App request and not a user request, unknown sender");
}
}
}
});
};
console.log("three");
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
</html>
为什么 ?