简体   繁体   中英

$facebook->getUser() keep returning null after facebook login redirection

I am getting an issue while trying to auth user through the graph API with the official php sdk.

Look simple as hell but I can not get it to work and getUser() keep returning null.

Here is my code reduced in the most simple form:

$facebook = new Facebook(array(
      'appId'  => 'ID',
      'secret' => 'SECRET',
      'cookie' => true
    ));

    $user = $facebook->getUser();

    if (!$user):
       $params = array('scope' => 'email','redirect_uri' => 'http://myredirecturi.com');
     ?>
        <a href=" <? echo $facebook->getLoginUrl($params); ?>">Login</a>
    <? endif; ?>

So when I click the login button I go to facebook and them I arrived on the redirect url like it should be.

I also have GET data: "code" and "state" so it is looking good, however I don't have a "signed_request" value.

Finally, $facebook->getUser() keep returning null.

What is wrong here ?

-Is the facebook object well initialized ? (should the 'cookie' setting be set to true ?)

-The redirect_uri is also not an https uri. Does it matter ?

-Should I look for something in the facebook app settings ?

Thanks !

Good answer here not sure if it is the same issue for you but worked for me. Basically until the user authorizes the app you can't get their Uid. So even if they are logged in the app still doesn't have access until they accept. Then UID will be returned. facebook->getUser() returns 0

如果其他任何人仍然遇到此问题,请确保您的应用仍不在沙盒模式下:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM