我想设置一个facebook php帖子到墙上,但在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 :(得分: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
}