javascript 如何使用访问令牌获取电子邮件地址和 Facebook 用户的一些基本信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21034839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:53:10  来源:igfitidea点击:

How do I use the access token to get email address and some basic info of facebook users

javascriptjqueryfacebookfacebook-graph-api

提问by madi

I have the follwing code and would like to take the email address and other details of facebook user. This is the code that I have done.

我有以下代码,并想获取 facebook 用户的电子邮件地址和其他详细信息。这是我所做的代码。

FB.login(function(response) {
      if (response.authResponse) {
         //updateUserInfo(fb_id);
        console.log(response.authResponse);
        updateUserInfo(response.authResponse.userID);
        $.ajax({
           dataType: "json",
           url: 'http://graph.facebook.com/'+response.authResponse.userID+'/ fields=id,name,birthday,email,gender,hometown,location',
           success: function(data){
                fb_data = data;
               console.log(data);
            }});
 },{scope:'email'});

I am unable to get get the following details:

我无法获得以下详细信息:

  1. birthday
  2. email
  3. Location
  4. hometown
  1. 生日
  2. 电子邮件
  3. 地点
  4. 家乡

However, I am able to get the first name and id.

但是,我能够获得名字和 ID。

If I am supposed to use the access token, how am i supposed to put it in the query? The email address is the vital information as my system identifies user by email address.

如果我应该使用访问令牌,我应该如何将它放入查询中?电子邮件地址是重要信息,因为我的系统通过电子邮件地址识别用户。

采纳答案by jacquard

You dont have to use the ajax call after FB.login, you can use FB.apidoc, which will ensure that the access token that you have obtained while logging in (requiring email access) will be used for accessing the data

FB.login后不必使用ajax调用,可以使用FB.apidoc,这将确保您在登录时获得的访问令牌(需要电子邮件访问权限)将用于访问数据

回答by amrendra

You need following permission from user to get the data from Facebook.

您需要获得用户的以下许可才能从 Facebook 获取数据。

  1. user_birthdayfor birthday
  2. emailfor email
  3. user_locationfor Location
  4. user_hometownfor hometown
  1. user_birthday生日
  2. 电子邮件电子邮件
  3. 位置的 user_location
  4. user_hometown为家乡

You can check thisor thisfor other permissions and uses.

您可以检查此以获取其他权限和用途。

Then you will get the access token once user click on your Login button and authorize your App.

然后,一旦用户单击您的登录按钮并授权您的应用程序,您将获得访问令牌。