[英]need help on posting on user wall
下面需要幫助的是我的應用程序的index.php代碼,我想在用戶使用OFFLINE_ACCESS和publish_stram授權我的應用程序后在用戶牆上發布
<?php
$app_id = "XXXXXXXXXX";
$app_secret = "XXXXXXX";
$canvas_page = "http://apps.facebook.com/esccounsel/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=read_stream publish_stream offline_access");
$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 {
echo ("Welcome User: " . $data["user_id"]);
}
?>
我想直接張貼在用戶牆上,請回答
offline_access
權限 熟悉PHP-SDK,並使用示例頁面中的代碼作為索引,例如:
<?php require '../src/facebook.php'; $facebook = new Facebook(array( 'appId' => 'XXXXXXX', 'secret' => 'XXXXXXXX', 'cookie' => true, )); $session = $facebook->getSession(); $loginUrl = $facebook->getLoginUrl(array( "req_perms" => "publish_stream" )); $me = null; if ($session) { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); echo "Welcome User: " . $me['name'] . "<br />"; $post_id = $facebook->api("/$uid/feed", "post", array("message"=>"Hello World!")); if(isset($post_id)) echo "A new post to your wall has been posted with id: $post_id"; } catch (FacebookApiException $e) { error_log($e); } } else { echo("<script> top.location.href='" . $loginUrl . "'</script>"); } ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.