如何在脸书 API 中获取用户位置和用户家乡

How to get user location and user hometown in facebook api?

本文关键字:用户 获取 位置 家乡 API      更新时间:2023-09-26

我已经在使用此脚本,但是当我使用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>

但无法获得家乡和位置,请帮忙举任何例子。

您使用了错误的权限,请尝试以下操作:

{ scope: 'email,user_birthday,user_location,user_hometown' }

另一件事,要访问家乡,请使用这个:

var hometown= response.hometown.name;

另外,不要/me;使用 fields 参数明确提及所需的字段;就像:/me?fields=hometown

图形 API 资源管理器