javascript 如何在facebook api中获取用户位置和用户家乡?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19853162/
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 to get user location and user hometown in facebook api?
提问by siva
I am already using this script but I didn't get hometown and location when I use API the hometown and location is undefined
message appears please give example code and how to get user mobile number in Facebook API:
我已经在使用这个脚本,但是当我使用 API 时我没有得到家乡和位置,家乡和位置是undefined
消息出现请给出示例代码以及如何在 Facebook API 中获取用户手机号码:
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
testAPI();
} else {
// cancelled
}
}, { scope: 'email,user_birthday,user_location,user_hometown' });
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.' + ' Email: ' + response.email + ' Facebook ID: ' + response.id);
//console.log('Good to see you, ' + response.name + '.');
var userfirstName=response.first_name;
var lastName=response.last_name;
var useremail=response.email;
var usersex=response.gender;
var userbithday=response.birthday;
var hometown= response.hometown.name;
var location= response.location.name;
alert(hometown);
});
}
}
<fb:login-button show-faces="false" width="200" max-rows="1" scope="email,user_birthday,user_location,user_hometown" onclick="testAPI();" onlogin="Log.info('onlogin callback')">
Sign Up with Facebook
</fb:login-button>
but can't get hometown and location, please help give any example.
但是不能得到家乡和位置,请帮忙举个例子。
回答by Sahil Mittal
You are using wrong permissions, try this:
您使用了错误的权限,请尝试以下操作:
{ scope: 'email,user_birthday,user_location,user_hometown' }
Another thing, to access the hometown use this:
另一件事,访问家乡使用这个:
var hometown= response.hometown.name;
Also, instead of /me
; mention explicitly the fields you want using the fields
parameter; just like: /me?fields=hometown
此外,而不是/me
; 使用fields
参数明确提及您想要的字段;就像:/me?fields=hometown