no age_range in facebook response (javascript sdk)

2019-08-28 07:06发布

I need to get age range for the user himself (not friend)

As per https://developers.facebook.com/docs/graph-api/reference/v2.1/user

user_range is part of the /me node. But, I decoded the response object and there is no age_range over there.

I am using facebook javascript sdk. Is age_range available? how? is it still accessible through the 'signed _request'?

2条回答
做自己的国王
2楼-- · 2019-08-28 07:38

I was accessing the /me node via the graph API.

I found out that the age_range is not returned with the root object but to get age_range, I need to issue the following API call

me?fields=age_range

This gives me a JSON obejct age_range that has min and max values.

查看更多
倾城 Initia
3楼-- · 2019-08-28 07:55

You'll have to explicitly tell the API that you need age_range, as part of the public profile (no special permissions required). The user's age range may be 13-17, 18-20 or 21+.

/* make the API call v.2.3 */
FB.api(
    "/me?fields=age_range",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);

read documentation https://developers.facebook.com/docs/graph-api/reference/age-range/

查看更多
登录 后发表回答