从Facebook登录按钮中未定义所有返回值

问题描述 投票:0回答:1

成功登录后,我尝试从用户处获取一些字段。所有这些都是undefinedname以外的ID。弹出窗口确实会问我授予的那些许可。

阅读这里的所有帖子,并提供了一个解决方案,除了使用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我得到一个错误:未捕获的ReferenceError:没有定义响应

javascript facebook-graph-api facebook-javascript-sdk
1个回答
0
投票

对于任何想知道的人,首先,阅读它的方式是:

  FB.api('/me', {fields: 'name,email'}, (response) => {
          console.log('name: ' + response.name);
          console.log('email: ' + response.email);
     });

二,要注意几点:

  1. 删除您的Facebook个人资料上的应用程序(在应用程序下),否则每次测试时,即使您希望添加更多权限,FB也会自动授予访问权限。
  2. 每次新测试都会从浏览器中删除缓存,因为FB将保持以前的状态并且更改不会生效。(有时甚至更新的部署也不会生效)
  3. 您应该与我一起部署您的网站 - 本地主机不使用FB,因为它们需要https。

测试Facebook有点麻烦。

© www.soinside.com 2019 - 2024. All rights reserved.