user1643121
user1643121

Reputation: 1

PHP sdk redirect after he have granted permission

I don't have very good skills in coding what i want to do is when i user visit my site and after he grant access to my app message will be posted to his wall and i want him to be redirected to some other url the wall post is working fine but after he grant permissions nothing happens only white page is shown this is the code what i have:

    <?php
require_once "./src/facebook.php";

$app_id = "xxxxxx";
$app_secret = "xxxxx";

// Init facebook api.
$facebook = new Facebook(array(
        'appId' => $app_id,
        'secret' => $app_secret,
        'cookie' => true
));

// Get the url to redirect for login to facebook
// and request permission to write on the user's wall.
$login_url = $facebook->getLoginUrl(
    array('scope' => 'publish_stream')
);

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


// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
    echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;

    exit;
}

// Do the wall post.
$facebook->api("/me/feed", "post", array(
    message => "test",
    picture => "http://s.ytimg.com/yt/img/doodles/teachers_day_yoodle-vflBKh2mG.png",
    link => "http://www.youtube.com/",
    name => "test",
    caption => "test"
));
?>

Upvotes: 0

Views: 563

Answers (1)

dythffvrb
dythffvrb

Reputation: 177

to redirect a user after granting permissions use this:

$user = $facebook->getUser();


if($user){
    // Get logout URL
    $logoutUrl = $facebook->getLogoutUrl();
}else{
    // Get login URL
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'         => 'publish_actions',
        'redirect_uri'  => 'http://mysite.com/success.html', //redirect user to this url
        ));
}

Upvotes: 1

Related Questions