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

Sunday, January 9, 2022

[FIXED] Permission to get user email with Facebook PHP SDK

 January 09, 2022     facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

I have a working integration with facebok api via PHP SDK and working login. Now I tried to add the permission for email as well with the following code, but when trying to connect/login to the app the email is not requested.

// login or logout url will be needed depending on current user state.
if ($me) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array(
    'req_perms' => 'email',
  ));
}

The error must be in this code since everything else works fine. Thanks!


Solution

Remove the comma you have after 'email' and redirect the browser to $loginUrl, like this:

$loginUrl = $facebook->getLoginUrl(
  array(
    'req_perms' => 'email'
  )
);

echo '<script>top.location="'.$loginUrl.'";</script>';
die();

EDIT

This was how it was done back in the day, now facebook have changed their API:s. For a more current solution, look at the other answers on this question.



Answered By - fredrik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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