0

我不是 Facebook 应用专家。我从 FB 网站获取了这段代码,并对其进行了修改以使其与我的应用程序 ID 一起使用(这是我唯一更改的内容。我还添加了一些警报)。然后我尝试从本地网页使用此代码(即:该页面在我的桌面上,但我的笔记本电脑已连接到 Internet)。

每当我运行此代码时,都会弹出一个浏览器弹出窗口,显示此错误:“MyAppName 发生错误。请稍后再试。”

有人能告诉我这里发生了什么吗?似乎 FB.getLoginStatus 也从未被调用过。

任何帮助表示赞赏。

// initialize the library with the API key
FB.init({ appId: 'myAppID',frictionlessRequests:true });

// fetch the status on load
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token 
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
alert("1. not");
// the user is logged in to Facebook, 
// but has not authenticated your app
} else {
alert("2. alert");
// the user isn't logged in to Facebook.
}
});

$('#login').bind('click', function() {
FB.login(handleSessionResponse);
});

$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});

$('#disconnect').bind('click', function() {
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
clearDisplay();
});
});

// no user, clear display
function clearDisplay() {
$('#user-info').hide('fast');
}

// handle a session response from any of the auth related calls
function handleSessionResponse(response) {
// if we dont have a session, just hide the user info
alert("entered handleSessionResponse");
if (response.authResponse) {
alert('Welcome!  Fetching your information.... ');
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
} else {
alert('User cancelled login or did not fully authorize.');
}
if (!response.session) {
clearDisplay();
return;
}
}
4

1 回答 1

0

您是否将属性更改为myAppID您正在使用的 Facebook 应用程序的 ID?

FB.init({ appId: 'myAppID',frictionlessRequests:true });

myAppID应该包含一个唯一的 Facebook 应用 ID,您可以在 Facebook 应用页面上获取该 ID 。也许您只是复制了代码而没有更改它。

于 2012-05-06T16:38:48.370 回答