2013-08-06 52 views
0

我想設置一個Facebook的PHP的帖子到牆上,但在Facebook身份驗證後,代碼只是不斷重定向與不同的令牌,任何人都可以幫助我嗎?非常感謝!!Facebook的身份驗證不斷重定向

這裏是我的樣本網址:http://for-winner.com/fff.php

require_once ("fb/src/facebook.php"); 

$facebook = new Facebook(array(
     'appId' => 'id', 
     'secret' => 'secret', 
     'cookie' => true 
    )); 

$attachment = array(
    'message' => 'hello', 

); 

$user = $facebook->getUser(); 
if($user == 0) { 
    $login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream")); 
    echo ("<script> top.location.href='".$login_url."'</script>"); 
} else { $token=$facebook->getAccessToken(); 

    try { 
     $ret_obj = $facebook->api('/me/feed', 'POST', $attachment); 
    } catch(FacebookApiException $e) { 
     $login_url = $facebook->getLoginUrl(array(
          'scope' => 'publish_stream' 
         )); 
     error_log($e->getType()); 
     error_log($e->getMessage()); 
    } 
} 

回答

0

使用此代碼,而不是 -

$canvas_page = "https://apps.facebook.com/APP_NAMESPACE/MY_CURRENT_PAGE.php; 
$auth_url = "https://www.facebook.com/dialog/oauth?client_id=APP_ID&redirect_uri=" . urlencode($canvas_page)."&scope=publish_stream"; 
$signed_request = $_REQUEST["signed_request"]; 
list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); 
if (empty($data["user_id"])) 
{ 
    echo("<script> top.location.href='" . $auth_url . "'</script>"); 
} 
else 
{ 
    // you code 
}