2012-10-06 61 views
0

我没有很好的编码技能,我想要做的是当我用户访问我的网站,并在他授予访问我的应用程序消息后将张贴到他的墙和我希望他被重定向到的墙后工作正常一些其他的url,但之后他授予权限没有任何反应只有白色页面显示这是代码我有:PHP sdk重定向后,他已授予权限

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

你从哪里得到$ params?它看起来像你从不同的地方复制粘贴的代码片段 检查Facebook的文档。这里也有一些例子 – dythffvrb

回答

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 
     )); 
}