简体   繁体   English

Facebook PHP SDK和页面选项卡; 授权过程后,getUser()始终返回0

[英]Facebook PHP SDK and Page Tabs; getUser() always returns 0 after authorization process

I'm a PHP developer and I have nice experience with Facebook PHP SDK, but this time I'm lost :( 我是一名PHP开发人员,并且对Facebook PHP SDK有很好的经验,但是这次我迷路了:(

My problem is the following: I'm developing a facebook page tab application with Laravel, a PHP framework. 我的问题如下:我正在使用PHP框架Laravel开发Facebook页面标签应用程序。 This is my code: 这是我的代码:

    //getting the Facebook class instance
    $facebook = IoC::resolve('facebook-sdk');

    if(!$facebook->getUser()){
        $pagetab_url = 'https://www.facebook.com/PAGEUSERNAME?sk=app_APPID';    

        $loginUrlParams = array(
               'scope' => 'publish_stream',
               'redirect_uri' => $pagetab_url
        );

        $loginUrl = $facebook->getLoginUrl($loginUrlParams);

        echo("<script> top.location.href='" . $loginUrl . "'</script>");
    }
    else{
        echo $facebook->getUser();
    }

This code generates an infinite loop, because $facebook->getUser() always returns zero. 此代码生成一个无限循环,因为$ facebook-> getUser()始终返回零。 AppId and AppSecret are correct, infact, if I change 'redirect_uri' to any page of my app domain, it works (for example: 'redirect_uri' => ' https://www.mysite.com/fb_callback '). 实际上,AppId和AppSecret是正确的,如果我将'redirect_uri'更改为我的应用程序域的任何页面,则它可以正常工作(例如:'redirect_uri'=>' https://www.mysite.com/fb_callback ')。

Additional details: the signed request is always null. 其他详细信息:签名的请求始终为null。 Do you have any idea? 你有什么主意吗?

Many thanks! 非常感谢!

EDIT This solved my problem Facebook iframe tab signed request always empty 编辑这解决了我的问题Facebook iframe选项卡签名的请求始终为空

I think rather than injecting a script which reloads the page, you need to give the user a chance to log into your app and authorize it. 我认为您无需注入重新加载页面的脚本,而是需要给用户提供登录到您的应用并对其进行授权的机会。

Am I missing something? 我想念什么吗? (You'll never get a result from $facebook->getUser() call unless the user is logged in AND has authorized your app). (除非用户登录并授权了您的应用,否则您永远不会从$ facebook-> getUser()调用中获得结果)。

Lastly, is there any reason you don't use: 最后,是否有您不使用的原因:

header('Location: '.$loginUrl) ?

Instead of injecting javascript? 而不是注入JavaScript?

Are you developing on more than one server? 您是否在多个服务器上进行开发? (Localhost and a test server perhaps?) Another possibility is that you are testing on two different domains (localhost vs stage.whatever.com, for example) and you need to give your app permission to work on both domains. (也许是Localhost和测试服务器?)另一种可能性是,您正在两个不同的域上进行测试(例如localhost vs stage.whatever.com),并且您需要授予您的应用程序许可权才能在这两个域上工作。

Basically, log errors, if any, from the getUser() call and see what that output is. 基本上,记录来自getUser()调用的错误(如果有),并查看该输出是什么。

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

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