Facebook 应用程序身份验证的 PHP 循环问题

发布于 2024-12-02 06:49:27 字数 1307 浏览 3 评论 0原文

我正在使用最新的 PHP-SDK(3.11),当用户第一次使用我的应用程序时,我遇到了问题。该应用程序进行无限循环。 当用户必须向应用程序授予权限时,他会被重定向到:

https://www.facebook.com/connect/uiserver.php?app_id=**myappId**&method=permissions.request&display=page&next=http%3A%2F%2Fapps.facebook.com%2F**myApp**%2F&response_type=code&state=**theSate**&canvas=1&perms=user_birthday%2Cuser_location%2Cuser_work_history%2Cuser_about_me%2Cuser_hometown

当他接受时,我返回以下链接:

http://apps.facebook.com/**myApp**/?error_reason=user_denied&error=access_denied&error_description=***The+user+denied+your+request.***&state=**theSate**#_

我不明白为什么当用户单击“允许”时访问被拒绝。

if ($this->fbUser) {
            .... Do Somthing
        } else {
            $this->loginUrl = $this->fb->facebook->getLoginUrl(array(
                        'scope' => implode(',', sfConfig::get('app_facebook_perms')
            ), 'next' => 'http://apps.facebook.com'. sfConfig::get('app_facebook_app_url')));


            $this->logMessage($this->loginUrl, 'info');
            sfConfig::set('sf_escaping_strategy', false);
        }

        <script type='text/javascript'>
            top.location.href = "echo $this->loginUrl ";
        </script>

I am using the latest PHP-SDK(3.11) and i have issues when users come on my app for the first time. The application make infinite loops.
When the user have to give permissions to the application, he is redirected to :

https://www.facebook.com/connect/uiserver.php?app_id=**myappId**&method=permissions.request&display=page&next=http%3A%2F%2Fapps.facebook.com%2F**myApp**%2F&response_type=code&state=**theSate**&canvas=1&perms=user_birthday%2Cuser_location%2Cuser_work_history%2Cuser_about_me%2Cuser_hometown

and when he accept i have the following link returned :

http://apps.facebook.com/**myApp**/?error_reason=user_denied&error=access_denied&error_description=***The+user+denied+your+request.***&state=**theSate**#_

i don't understand why the access is denied when the user click on "allow".

if ($this->fbUser) {
            .... Do Somthing
        } else {
            $this->loginUrl = $this->fb->facebook->getLoginUrl(array(
                        'scope' => implode(',', sfConfig::get('app_facebook_perms')
            ), 'next' => 'http://apps.facebook.com'. sfConfig::get('app_facebook_app_url')));


            $this->logMessage($this->loginUrl, 'info');
            sfConfig::set('sf_escaping_strategy', false);
        }

        <script type='text/javascript'>
            top.location.href = "echo $this->loginUrl ";
        </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知在何时 2024-12-09 06:49:27

尝试这样的操作,因为您需要以一种或另一种方式存储访问令牌。很难从该片段中知道您在做什么(或没有做什么)。

<?php  
# We require the library  
require("facebook.php");  

# Creating the facebook object  
$facebook = new Facebook(array(  
    'appId'  => 'APP_ID_HERE',  
    'secret' => 'APP_SECRET_HERE',  
    'cookie' => true  
));  

# Let's see if we have an active session  
$session = $facebook->getUser();  

if(empty($session)) {  
    # There's no active session, let's generate one  
    $url = $facebook->getLoginUrl(array(  
        "response_type"=>"token", //Can also be "code" if you need to 
        "scope" => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos' , 
        "redirect_uri"=> "http://test.com" //Your app callback url 
    ));  
    header("Location: $url");  
    exit;  
}  
// user is logged in  

Try something like this, since you need to store the access token, one way or another. Hard to know what you are doing (or not doing) from that snippet.

<?php  
# We require the library  
require("facebook.php");  

# Creating the facebook object  
$facebook = new Facebook(array(  
    'appId'  => 'APP_ID_HERE',  
    'secret' => 'APP_SECRET_HERE',  
    'cookie' => true  
));  

# Let's see if we have an active session  
$session = $facebook->getUser();  

if(empty($session)) {  
    # There's no active session, let's generate one  
    $url = $facebook->getLoginUrl(array(  
        "response_type"=>"token", //Can also be "code" if you need to 
        "scope" => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos' , 
        "redirect_uri"=> "http://test.com" //Your app callback url 
    ));  
    header("Location: $url");  
    exit;  
}  
// user is logged in  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文