2

如果存在,我想将图片发布到相册“Wall Photos”中,否则如果“Wall Photos”不存在,则发布没有相册的图像(APPNAME PHOTOS)。

$album = $facebook->api('/'PAGEID'/albums'); 
foreach($album['data'] as $album){
 if($album['name'] == 'Wall Photos'){ 
  $album_post = $album['id']; 
 }
}
$risultato['pagina'][$pagina['id']] = $facebook->api('/'.$album_post.'/photos', 'POST',           array( 'access_token' => PAGETOKEN, 'source' => '@' . IMAGE, 'message' => TEXT ) );
if(!isset($album_post)){
 $risultato['pagina'][$pagina['id']] = $facebook->api('/'.$pagina['id'].'/photos',   'POST', array(
                'access_token'  => $pagina['token'],
                'source' => '@' . IMAGEPATH,
                'message' => TEXT
        )
    );
    }else{
   $risultato['pagina'][$pagina['id']] = $facebook->api('/'.$album_post.'/photos', 'POST', array(
                'access_token'  => $pagina['token'],
                'source' => '@' . realpath("../img_post/".$post['Immagine']),
                'message' => $post['Testo']
        )
    );
    }

但我收到该错误:第 1237 行的 base_facebook.php 中抛出的专辑 ID 无效

4

1 回答 1

1

id 字段应该是 $album 对象的一个​​元素。事实上,它是第一个。

https://developers.facebook.com/docs/reference/api/album/

顺便说一句,您还应该使用 BREAK 命令,以便在满足条件时退出 foreach 循环。

foreach($album['data'] as $album){
 if($album['name'] == 'Wall Photos'){ 

// To debug:

echo "<pre>";
print_r($album);
echo "</pre>";

// End debug

  $album_post = $album['id']; 
  break; 
 }
 }

这应该产生类似的东西:

Array
(
[id] => xxxxxxxxxxxxxxx
[from] => Array
    (
        [category] => Community
        [name] => xxxxxxxxxxxxx
        [id] => xxxxxxxxxxxxx
    )

[name] => xxxxxxxxxx
[description] => xxxxxxxxxxxxxxxx
[link] => http://www.facebook.com/album.php?xxxxxxxxxxxxxxxxxxxxxx
[cover_photo] => xxxxxxxxxxxxxx
[privacy] => everyone
[count] => 4
[type] => normal
[created_time] => 2012-12-11T14:56:06+0000
[updated_time] => 2012-12-11T14:56:22+0000
[can_upload] => 1
)

这至少应该给你一个关于发生了什么的线索。

于 2012-12-11T21:26:20.703 回答