using FB.data.query not getting any response back

最后都变了- 提交于 2019-12-11 17:09:16

问题


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:


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.



来源:https://stackoverflow.com/questions/5773841/using-fb-data-query-not-getting-any-response-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!