FB.api在FB.init之後調用時不起作用。這裏是代碼片段我用:FB.api在FB.init後調用時不起作用
window.fbAsyncInit = function() {
FB.init({
appId : window.APP_ID,
status : true,
cookie : true,
oauth : true,
channelUrl : window.MASTER_URL + "channel",
frictionlessRequests : true
});
window.COMPANY.init();
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
,這裏是我的COMPANY.init()和COMPANY.fetchAllFriends():
friends: new Array(),
init : function() {
// TODO
COMPANY.fetchAllFriends();
FB.Canvas.setSize($(document).height());
FB.Canvas.setAutoGrow();
},
fetchAllFriends : function() {
FB.api('/me/friends', function(response) {
if (!response || response.error) {
return;
}
COMPANY.friends = new Array();
$.each(response.data, function(index, value) {
COMPANY.friends.push(value.id);
});
});
},
,其中在fetchAllFriends響應包含錯誤,說:「工作中的接入令牌必須用於查詢有關當前用戶的信息。「我確定(通過瀏覽器調試器)在調用FB.api之前調用FB.init。
任何幫助將不勝感激!
謝謝,但這並不能解釋爲什麼'fetchAllFriends'方法(如上面定義的)在頁面加載後調用時完美工作,而不顯式調用FB.getLoginStatus或在調用中放置一個令牌。 – 2011-12-13 18:59:30