Question

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>
Was it helpful?

Solution

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' ) ;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top