using FB.data.query not getting any response back

2019-09-06 10:39发布

I am trying to get the user gender and birth date through the following:

   FB.api('/me', function(response) {
                var query = FB.Data.query('select birthday, gender from user where owner={0}',
                       response.id);

                query.wait(function(rows) {
                    console.log(rows[0].birthday);
                    console.log(rows[0].gender);
                    alert(rows[0].birthday);
                    alert(rows[0].gender);
                });
            });

However, I see nothing on the console and there is no alert. Why is this?

1条回答
爷的心禁止访问
2楼-- · 2019-09-06 11:12

If you want the birthday and gender of an authenticated user (/me) you can just access the User Object like this:

FB.api('/me', function(response) {
    console.log(response.birthday);
    console.log(response.gender);
    alert(response.birthday);
    alert(response.gender);
});

If you want the birthday and gender to come from the user table you can't use the "gender" field because it doesn't exist. Use "sex" instead.

FB.api('/me', function(response) {
  var query = FB.Data.query('select birthday, sex from user where uid={0}', response.id);

   query.wait(function(rows) {
         console.log(rows[0].birthday);
         console.log(rows[0].gender);
         alert(rows[0].birthday);
         alert(rows[0].sex);
        });
});

You received no response because you were trying to access a field that doesn't exist.

查看更多
登录 后发表回答