我没有很好的编码技巧,我想要做的就是当我用户访问我的网站时,他授权访问我的应用程序消息将被发布到他的墙上,我希望他被重定向到一些其他网址墙贴工作正常,但在他授予权限之后没有任何事情发生只有白页显示这是我的代码:
<?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"
));
?>
答案 0 :(得分: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
));
}