简体   繁体   English

$ facebook-> getUser()在Facebook登录重定向后继续返回null

[英]$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. 尝试通过带有官方php sdk的图形API对用户进行身份验证时遇到问题。

Look simple as hell but I can not get it to work and getUser() keep returning null. 看起来很简单,但是我无法正常工作,并且getUser()始终返回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. 因此,当我单击登录按钮时,我去了Facebook,他们到达了重定向网址,就像应该的那样。

I also have GET data: "code" and "state" so it is looking good, however I don't have a "signed_request" value. 我也有GET数据:“代码”和“状态”,因此看起来不错,但是我没有“ signed_request”值。

Finally, $facebook->getUser() keep returning null. 最后,$ facebook-> getUser()继续返回null。

What is wrong here ? 这是怎么了

-Is the facebook object well initialized ? -facebook对象初始化正确吗? (should the 'cookie' setting be set to true ?) (应将“ cookie”设置设置为true吗?)

-The redirect_uri is also not an https uri. -redirect_uri也不是https uri。 Does it matter ? 有关系吗 ?

-Should I look for something in the facebook app settings ? -我应该在facebook应用程序设置中寻找什么吗?

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. 基本上,直到用户授权该应用程序,您才能获得其Uid。 So even if they are logged in the app still doesn't have access until they accept. 因此,即使他们已登录,应用也仍然无法访问,直到他们接受。 Then UID will be returned. 然后将返回UID。 facebook->getUser() returns 0 facebook-> getUser()返回0

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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