Facebook php sdk:请求链接许可,而不是重定向

发布于 2024-12-27 14:48:03 字数 2283 浏览 1 评论 0原文

我想更改我的代码,首先它会检查用户是否喜欢该页面。此后(如果是)将会出现一个问题,要求接受条款,如果他点击接受按钮,Facebook 权限请求对话框将会出现。我该怎么做?

问题是,每次用户单击应用程序链接时,$user 变量始终为 false,但他已登录......

<?php
require 'facebook.php';

$facebook = new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'yyyyy',
'baseUrl' => 'http://hosting.address/',
'appBaseUrl' => 'http://apps.facebook.com/app-name/',
'fileUpload' => 'true',
));

// Get User ID
$user = $facebook->getUser();

$params = array(
  scope => 'publish_stream,user_photos',
  redirect_uri => 'http://www.facebook.com/xxxxx?sk=app_yyyyy&app_data=1'
    );

$signed_request = $facebook->getSignedRequest();
$app_data = $signed_request["app_data"];


?>
                    <!doctype html>
                    <html xmlns:fb="http://www.facebook.com/2008/fbml">
                    <head>
                    <title>the title</title>
                    </head>
                    <body>
<?php if ($user){

    try {
        $user_profile = $facebook->api('/me');
        $likes = $facebook->api("/me/likes/123123123"); //page ID

            if( !empty($likes['data']) ){

                $scope = 'publish_stream,user_photos';
                $scope_params = explode(',',$scope);

                $permissions = $facebook->api("/me/permissions");
                    if( array_key_exists('publish_stream', $permissions['data'][0]) &&  array_key_exists('user_photos', $permissions['data'][0]) && isset($app_data)) {


                    } else {

echo "<a href=\"/redirect.php\">accept</a></td>";
echo "<a href=\"http://www.facebook.com/pageurl\">deny</a></td>";

                    }
            }else{
                echo "<img width=\"520px\" src=\"no-fan.jpg\" />";
            }

    } catch (FacebookApiException $e) {
        echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
        $user = null;
        }
    }

    if ($user) {
        } else {
            $loginUrl = $facebook->getLoginUrl($params);
            echo '<script type="text/javascript">top.location.href = "'.$loginUrl .'";</script>';
        }

        ?>

</body>
</html>

I want to change my code so, that first it will check if the user has liked the page. After this (if yes) a question will come up, to accept the terms and if he clicks on the accept button the Facebook permissions request dialog will come up. How can i do this?

The problem is that everytime a user clicks on the app link the $user variable is always false, but he is logged in...

<?php
require 'facebook.php';

$facebook = new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'yyyyy',
'baseUrl' => 'http://hosting.address/',
'appBaseUrl' => 'http://apps.facebook.com/app-name/',
'fileUpload' => 'true',
));

// Get User ID
$user = $facebook->getUser();

$params = array(
  scope => 'publish_stream,user_photos',
  redirect_uri => 'http://www.facebook.com/xxxxx?sk=app_yyyyy&app_data=1'
    );

$signed_request = $facebook->getSignedRequest();
$app_data = $signed_request["app_data"];


?>
                    <!doctype html>
                    <html xmlns:fb="http://www.facebook.com/2008/fbml">
                    <head>
                    <title>the title</title>
                    </head>
                    <body>
<?php if ($user){

    try {
        $user_profile = $facebook->api('/me');
        $likes = $facebook->api("/me/likes/123123123"); //page ID

            if( !empty($likes['data']) ){

                $scope = 'publish_stream,user_photos';
                $scope_params = explode(',',$scope);

                $permissions = $facebook->api("/me/permissions");
                    if( array_key_exists('publish_stream', $permissions['data'][0]) &&  array_key_exists('user_photos', $permissions['data'][0]) && isset($app_data)) {


                    } else {

echo "<a href=\"/redirect.php\">accept</a></td>";
echo "<a href=\"http://www.facebook.com/pageurl\">deny</a></td>";

                    }
            }else{
                echo "<img width=\"520px\" src=\"no-fan.jpg\" />";
            }

    } catch (FacebookApiException $e) {
        echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
        $user = null;
        }
    }

    if ($user) {
        } else {
            $loginUrl = $facebook->getLoginUrl($params);
            echo '<script type="text/javascript">top.location.href = "'.$loginUrl .'";</script>';
        }

        ?>

</body>
</html>

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

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

发布评论

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

评论(1

生寂 2025-01-03 14:48:03

尝试遵循这个优秀的示例:

http://www.jelecos.com /default/blog/11-04-18/Facebook_PHP_SDK_Fangate_Creation.aspx

然后在 fanpage.php 上添加代码来要求他们登录。

Try following this excellent example:

http://www.jelecos.com/default/blog/11-04-18/Facebook_PHP_SDK_Fangate_Creation.aspx

Then on the fanpage.php have your code to ask them to log in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文