所有 return 值均未在 Facebook 登录按钮中定义
All return values are undefined from Facebook log in button
登录成功后,我尝试从用户那里获取一些字段。
除了 name
和 ID
之外,它们都是 undefined
。弹出窗口确实询问了我授予的权限。
阅读此处的所有帖子,但未提供除使用 tokens
(?) 之外的其他解决方案,我不确定如何使用,并且从未在 FB 示例中看到。
FB.login(
function(response) {
if (response.status === "connected") {
console.log("connected");
console.log("Access Token: " + response.authResponse.accessToken);
testAPI();
} else {
console.log("not connected");
}
},
{ scope: "email,user_age_range,user_friends" }
);
function testAPI() {
console.log("Welcome! Fetching your information.... ");
FB.api("/me", function(response) {
console.log("name: " + response.name);
console.log("email: " + response.email);
console.log("id: " + response.id);
console.log("friends: " + response.user_friends);
console.log("age: " + response.user_age_range);
console.log("end");
});
}
如果我打印 response
我得到一个错误:
未捕获的引用错误:未定义响应
对于任何想知道的人,首先,阅读方式是:
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log('name: ' + response.name);
console.log('email: ' + response.email);
});
其次,注意几点:
在您的 Facebook 个人资料中删除您的应用程序(在应用程序下),否则每次您测试时,即使您希望添加 更多 权限,FB 也会自动授予访问权限.
每次新测试都从浏览器中删除缓存,因为 FB 将保持以前的状态并且更改不会生效。(有时,即使更新的部署也不会)
您应该和我一起部署您的网站 - 本地主机无法使用 FB,因为它们需要 https。
测试 Facebook 有点麻烦。
登录成功后,我尝试从用户那里获取一些字段。
除了 name
和 ID
之外,它们都是 undefined
。弹出窗口确实询问了我授予的权限。
阅读此处的所有帖子,但未提供除使用 tokens
(?) 之外的其他解决方案,我不确定如何使用,并且从未在 FB 示例中看到。
FB.login(
function(response) {
if (response.status === "connected") {
console.log("connected");
console.log("Access Token: " + response.authResponse.accessToken);
testAPI();
} else {
console.log("not connected");
}
},
{ scope: "email,user_age_range,user_friends" }
);
function testAPI() {
console.log("Welcome! Fetching your information.... ");
FB.api("/me", function(response) {
console.log("name: " + response.name);
console.log("email: " + response.email);
console.log("id: " + response.id);
console.log("friends: " + response.user_friends);
console.log("age: " + response.user_age_range);
console.log("end");
});
}
如果我打印 response
我得到一个错误:
未捕获的引用错误:未定义响应
对于任何想知道的人,首先,阅读方式是:
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log('name: ' + response.name);
console.log('email: ' + response.email);
});
其次,注意几点:
在您的 Facebook 个人资料中删除您的应用程序(在应用程序下),否则每次您测试时,即使您希望添加 更多 权限,FB 也会自动授予访问权限.
每次新测试都从浏览器中删除缓存,因为 FB 将保持以前的状态并且更改不会生效。(有时,即使更新的部署也不会)
您应该和我一起部署您的网站 - 本地主机无法使用 FB,因为它们需要 https。
测试 Facebook 有点麻烦。