在粉丝页面相册上发布照片


Publishing Photo on Fan Page album

我有一个PHP脚本,可以在我的facebook粉丝页面墙上上传图片+描述+其他详细信息。但我需要的是上传专辑内部。我在网上到处找这个答案,这个教程是我迄今为止最接近的。

这是我的代码:

$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

如果有人知道如何在相册中张贴图片,请帮助我;)

在这里,此代码检查具有您想要的名称的相册是否存在,如果不存在,则创建一个新相册:

//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);