APP在redirect_url上显示空白页面

发布于 2024-12-25 21:57:14 字数 3787 浏览 1 评论 0原文

我有一个 Facebook PHP SDK 应用程序处于开发阶段,但我陷入了困境...... 应用程序的逻辑是这样的:

首先用户必须喜欢该页面(应用程序就在此)//效果很好:) 之后是权限请求 如果授予权限:app_data 变量将被传递,用户会收到图片。

app_data 变量是必需的,因为如果用户在再次授予权限后单击该应用程序,它会自动获取新图片。而 app_data 则不然。

我的问题是这个链接:

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

<a href="<?php echo $facebook->getLoginUrl($params); ?>">Accept</a>

如果我点击它,应用程序会显示空白页面,并且什么也没有发生...:( 在直接调用时,该应用程序运行时没有任何错误。

有人可以帮我吗?

// 对不起我的英语...

谢谢!

整个index.php是:

这是整个index.php:

<?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>
                    <style>
                        a:link    {color:#ffffff;}
                        a:visited {color:#ffffff;}
                        a:hover   {color:#ececec;}
                        a:active  {color:#1f1f1f;}
                        a:link    {text-decoration: none}
                    </style>
                    </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)) {


                        $file = "1.jpg";
                        $message = 'bla bla';

                        $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                                                        'source' => '@' . $file,
                                                                        'message' => $message,
                                                                    )
                                                                );
                        echo "<img width=\"520px\" src=\"1.jpg\" />";
                    } else {
                    ?>
<a href="<?php echo $facebook->getLoginUrl($params); ?>">accept</a></td>
<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 have a Facebook PHP SDK APP in development phase and i'm stuck on something...
The logic of the APP is this:

first the user have to like the page (app is on this) // works very well :)
after that comes the permissions request
if permission is granted: the app_data variable is pass through and the user recieves a picture.

app_data variable is necessary because, if the user clicks the app after permission granted again, it gets new picture automaticly. with the app_data don't.

my problem is this link:

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

<a href="<?php echo $facebook->getLoginUrl($params); ?>">Accept</a>

If i click on it, the app shows blank page, and nothing happening... :(
On direct call, that app runs without any error.

Can someone help me out?

// sorry for my english...

Thank you!

and the whole index.php is:

this is the whole index.php:

<?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>
                    <style>
                        a:link    {color:#ffffff;}
                        a:visited {color:#ffffff;}
                        a:hover   {color:#ececec;}
                        a:active  {color:#1f1f1f;}
                        a:link    {text-decoration: none}
                    </style>
                    </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)) {


                        $file = "1.jpg";
                        $message = 'bla bla';

                        $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                                                        'source' => '@' . $file,
                                                                        'message' => $message,
                                                                    )
                                                                );
                        echo "<img width=\"520px\" src=\"1.jpg\" />";
                    } else {
                    ?>
<a href="<?php echo $facebook->getLoginUrl($params); ?>">accept</a></td>
<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-01 21:57:14

当我深入研究 Facebook 应用程序的世界时,我曾经遇到过这种情况。

我最终所做的是对于我的 redirect_uri 我在我的域上使用了一个页面,例如 https://domain.com/facebook/redirect.php 并在redirect.php中我会有:

// user didn't give app permissions
if (isset($_GET['error_reason']))
{
    header( 'Location: http://www.facebook.com/FANPAGE' ) ;
}
else 
{
    header( 'Location: http://www.facebook.com/XXXXX?sk=app_YYYYYY' ) ;
}

I've had this before when I was delving into the world of Facebook apps.

What I eventually done was for my redirect_uri I used a page on my domain, e.g. https://domain.com/facebook/redirect.php and in redirect.php I would have:

// user didn't give app permissions
if (isset($_GET['error_reason']))
{
    header( 'Location: http://www.facebook.com/FANPAGE' ) ;
}
else 
{
    header( 'Location: http://www.facebook.com/XXXXX?sk=app_YYYYYY' ) ;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文