0

我在编码方面没有很好的技能我想做的是当我用户访问我的网站并且在他授予对我的应用程序的访问权限后,消息将被发布到他的墙上,我希望他被重定向到墙上的其他 URL帖子工作正常,但在他授予权限后什么都没有发生,只显示白页这是我拥有的代码:

    <?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"
));
?>
4

1 回答 1

1

在授予权限后重定向用户使用这个:

$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
        ));
}
于 2012-10-06T11:51:22.873 回答