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
How do I use the access token to get email address and some basic info of facebook users
提问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:
我无法获得以下详细信息:
- birthday
- Location
- hometown
- 生日
- 电子邮件
- 地点
- 家乡
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
回答by amrendra
You need following permission from user to get the data from Facebook.
您需要获得用户的以下许可才能从 Facebook 获取数据。
- user_birthdayfor birthday
- emailfor email
- user_locationfor Location
- user_hometownfor hometown
- user_birthday生日
- 电子邮件电子邮件
- 位置的 user_location
- 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.
然后,一旦用户单击您的登录按钮并授权您的应用程序,您将获得访问令牌。