siv*_*iva 10 javascript jsp facebook facebook-graph-api facebook-javascript-sdk
我已经在使用这个脚本,但是当我使用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>
但不能得到家乡和位置,请帮忙举个例子.
Sah*_*tal 21
您使用了错误的权限,请尝试以下操作:
{ scope: 'email,user_birthday,user_location,user_hometown' }
另一件事,访问家乡使用这个:
var hometown= response.hometown.name;
而且,而不是/me; 使用fields参数明确提到您想要的字段; 就像:/me?fields=hometown
| 归档时间: | 
 | 
| 查看次数: | 27817 次 | 
| 最近记录: |