我在Facebook上有一个应用程序,我选择了一张图片,我可以上传到与该应用程序相关的相册。
我找到了一些关于它的代码,但直到现在,我只能上传到我的个人帐户。
使用此代码,我可以获得该应用程序的所有相册详细信息:
$facebook->api('/app_id/albums?access_token='.$acces_token);
这很酷,我得到一份清单,但在此之后,我会做以下事情:
$upload_photo = $facebook->api('/'.$album_id.'/photos?access_token='.$acces_token, 'post', $photo_details);
我总是得到以下的例外: 致命错误:未捕获OAuthException:(#100)
中引发的专辑所有者的ID无效有什么问题?! 也许我没有正确的权限?或者我错过了什么?
我甚至试过这个:
$create_album = $facebook->api('/app_id/albums?access_token='.$acces, 'post', $album_details);
$album_uid = $create_album['id'];
$upload_photo = $facebook->api('/'.$album_uid.'/photos?access_token='.$acces, 'post', $photo_details);
答案 0 :(得分:0)
试试这个!!它创建了一个新专辑,然后在该特定专辑中发布了一张照片..
$post_login_url = "http://apps.facebook.com/yourapp/thefile";
$album_name = 'name of Album';
$album_description = 'something about album';
$code = $_REQUEST["code"];
$facebook->setFileUploadSupport(true);
//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 = $facebook->getAccessToken();
// Create a new album
$graph_url = "https://graph.facebook.com/me/albums?"
. "access_token=". $access_token;
$postdata = http_build_query(
array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=>
'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false,
$context));
// Get the new album ID
$album_id = $result->id;
//Show photo upload form and post to the Graph URL
$graph_url = "https://graph.facebook.com/". $album_id
. "/photos?access_token=" . $access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url. ' "method="POST">';
echo 'Adding photo to album: ' . $album_name .'<br/><br/>';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message" type="text"
value=""><br/><br/>';
echo '<input type="submit" value="Upload" /><br/>';
echo '</form>';
echo '</body></html>';
}
?>