PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Facebook SDK Invalid Scopes error

 February 04, 2022     facebook-graph-api, facebook-php-sdk     No comments   

Issue

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.



Answered By - Ricardo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing