我有一个PHP脚本,可以在我的脸书网页面墙上上传图片+说明+其他详细信息。 但我需要的是上传INSIDE一个专辑。 我正在网上寻找这个答案,this tutorial是我到目前为止最接近的。
这是我的代码:
$params = array(
"access_token" => $page_token,
"message" => "#php #facebook",
"link" => "www.domain.com.br",
"description" => "Buy this now!",
"source" => "@" . $path,
);
try {
$ret = $fb->api('/'.$album_id . '/photos', 'POST', $params);
echo 'Successfully posted to Facebook Fan Page';
} catch(Exception $e) {
echo $e->getMessage();
}
我已尝试将此$ret = $fb->api('/'.$fanpage_id . '/photos', 'POST', $params);
路径更改为此路径:$ret = $fb->api('/'.$fanpage_id.'/'.$album_id . '/photos', 'POST', $params);
及类似内容。
但它返回(#240) The target_id references an inactive user
,因为fb API认为$album_id
是$fanpage_id
。
如果有人知道如何在相册中张贴图片,请帮助我;)
答案 0 :(得分:0)
就是这样,这段代码会检查你想要的名字是否存在,如果没有,那么就会创建一个新的:
//Check if the album exists just change PAGE_ID to the ID of your page and NAME_OF_YOUR_ALBUM to the name of the album where you want to upload the photo
$fql = "SELECT object_id FROM album WHERE owner = PAGE_ID AND name='NAME_OF_YOUR_ALBUM'";
$album_exists = $this->facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
'access_token' => $accessToken
));
if(array_key_exists(0, $album_exists)){
//the album with that name exists, let's save his ID
$album_uid = $album_exists[0]['object_id'];
}else{
//We don't have an album with that name, let's create an album
$album_details = array('name'=> 'NAME_OF_YOUR_ALBUM');
$create_album = $this->facebook->api('/'.$page_id.'/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
}
//details of the photo you want to upload
$photo_details = array('message'=> 'This is a fantastic photo');
$file='PATH_TO_YOUR_FILE/NAME_FILE.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file); //get the real path
//Upload the photo to the album you've just created or the one you wanted
$upload_photo = $this->facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);