Ad

Unable To Request User_age_range From Facebook

- 1 answer

I'm trying to get the user age_rage from facebook login. [Android]

I requested Facebook user permission using this code

LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_age_range", "email"))

I tested it with 2 facebook account.

With the account A (created 2 years ago), I couldn't get the age_range.

With the account B (created recently), I get the age_range just fine.

And here is the code I use:

LoginManager.getInstance().loginBehavior = LoginBehavior.NATIVE_WITH_FALLBACK
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_age_range", "email"))
LoginManager.getInstance().registerCallback(callbackManager, object : FacebookCallback<LoginResult> {
        override fun onCancel() { ... }

        override fun onError(error: FacebookException) {...}

        override fun onSuccess(result: LoginResult) {
            GraphRequest(
            result.accessToken,
            "me?fields=name,email,age_range&format=json&access_token=${result.accessToken}",
            null, 
            HttpMethod.GET ,
            { response ->
               safeLog("SAFE_LOG", response.jsonObject.toString())
            }).executeAsync()
        }
    })

I'm pretty sure the problem is Facebook didn't grant me that user_age_range permission because, on the asking permission dialog on account A, the age_range wasn't listed at all but it was listed on account B.

Could you guys tell me what went wrong in my code?

UPDATE:

The solution I found before doesn't work anymore but I found the difference between 2 accounts.

The one which has age_range have access token source FACEBOOK_APPLICATION_SERVICE

The one which doesn't have age_range have access token source FACEBOOK_APPLICATION_WEB

I've already researched from the official doc here https://developers.facebook.com/docs/reference/android/current/class/AccessTokenSource

but I still have no idea what's causing the problem?

Ad

Answer

I'm pretty sure the problem is Facebook didn't grant me that user_age_range permission because, on the asking permission dialog on account A, the age_range wasn't listed at all but it was listed on account B.

AFAIK, There is nothing wrong with your SDK integration. The thing is there are certain permission which is private to the user(An individual Facebook user can decide whether age should be seen to the public or not) Now if the user didn't make the age as public from the settings. Even though app is asking for age permission facebook SDK will not be able to share it with you. However, on the other end, if logged in facebook user provided public access of age from his/her Facebook account, your app can get the age-related information upon accepting the permission dialog from the SDK.

I hope it makes sense to you.

Ad
source: stackoverflow.com
Ad