FB API GRAPH:为什么我无法捕获用户电子邮件?

时间:2019-02-27 10:55:24

标签: javascript facebook-graph-api facebook-javascript-sdk

我正试图检索用户登录我的Web应用程序的电子邮件;这是我的代码:

  FB.api('/me', function(response) {
    console.log(response.name + ', ' + response.email);
  });

用户名正确,但电子邮件结果为

  

未定义

我要去哪里错了?

1 个答案:

答案 0 :(得分:1)

https://developers.facebook.com/docs/reference/javascript/FB.login/v3.2

在登录过程中询问@Component class Prototype { @Autowired private Repository repository; // Here Session is part of javx.websocket package and cannot be added as part of // Java configuration class with a @Bean annotation // In this case how can I use constructor injection? private Session session; Prototype(Session session) { this.session = session; } } @Component class PrototypeClient { @Autowired private ApplicationContext context; private void createNewPrototype(Session session) { Prototype prototype = context.getBean(Prototype.class, session); } } @ServerEndpoint(value = "/resources") class WebSocketController { private PrototypeClient client = ApplicationContext.getBean(PrototypeClient.class); @OnMessage void handleMessage(Session session, String message) { client.createNewPrototype(session); } } 权限:

email

此外,您还需要询问要获取的字段:

FB.login((response) => {
  // handle the response
}, {scope: 'email'});

确保用户甚至有电子邮件,这不是必需的。并确保您确实在登录弹出窗口中被要求提供FB.api('/me', {fields: 'name,email'}, (response) => { console.log(response.name + ', ' + response.email); }); 权限。

侧面注意:我只会使用email,因此您可以看到整个对象,而不是某些console.log(response)值。