我從Facebook頁面獲取代碼以將照片發佈到用戶的牆上(帳戶)。使用圖形API向Facebook發佈圖像[已解決]
下面是我PostToFB.php文件:
<?php
include_once "facebook.php";
ini_set("display_errors",0);
//configuring application to post.
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$post_login_url = "YOUR_REDIRECT_URL";
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if(empty($code)){
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($post_login_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url
. "'</script>");
}
else {
$token_url="https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// Show photo upload form to user and post to the Graph URL
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url .' "method="POST">';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo '<input type="submit" value="Upload"/><br/>';
echo '</form>';
echo '</body></html>';
}
?>
但是,這是行不通的。我得到下面輸出:
{
"error": {
"message": "(#200) Permissions error",
"type": "OAuthException",
"code": 200
}
}
你能幫我解決這個問題嗎?
謝謝,
這工作對我很好。您是否使用管理員帳戶使用此功能? –
是使用我創建應用的帳戶。 –
@SahilMittal你對我的問題有任何解決方案嗎? 我無法找到問題... –