Search code examples
facebook-graph-apifacebook-php-sdk

Facebook SDK Invalid Scopes error


I'm trying to get user's birthday but as soon as I add the user_birthday permission I get an error Invalid Scopes: user_birthday. This message is only shown to developers...

I have thought that it was deprecated first but found nothing about it, also 3.0's documentation has the user_birthday permission. (HERE)

$fb = new Facebook\Facebook([
    'app_id' => 'XXXXXXXXXXXXXXX',
    'app_secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXX',
    'default_graph_version' => 'v3.0',
]);

$helper = $fb->getRedirectLoginHelper();

$permissions = ['email', 'user_birthday'];
$loginUrl = $helper->getLoginUrl('https://mywebsite.com/callback', $permissions);

$loginUrlFinal = 'https://www.facebook.com/dialog/oauth?client_id=XXXXXXXXXXXXXXX&redirect_uri='.$loginUrl.'&state='.urlencode($fb_params);

After this error about Invalid Scopes I'm redirected to my callback file with a "Bad request" error.

if (! isset($accessToken)) {
    if ($helper->getError()) {
        header('HTTP/1.0 401 Unauthorized');
        echo "Error: " . $helper->getError() . "\n";
        echo "Error Code: " . $helper->getErrorCode() . "\n";
        echo "Error Reason: " . $helper->getErrorReason() . "\n";
        echo "Error Description: " . $helper->getErrorDescription() . "\n";
    } else {
        header('HTTP/1.0 400 Bad Request');
        echo 'Bad request';
    }
    exit;
}

EDIT: This happens with almost any permission I add, the only one worked so far is just email.

A request to OpenGraph with ?fields=email,user_birthday returns no birthday while id, name, email are working fine. I guess this happens because I did not approve the user_birthday permission but how can I do that if the permission screen is not opening due to Invalid Scopes?


Solution

  • After long hours of research, I found out that this was due to my app being "Live". Looks like only apps that are currently in development mode will have permissions working.

    Hope it will help someone.