张贴墙照片 - Facebook Open Graph - Php Sdk

时间:2012-10-12 11:44:27

标签: php facebook sdk

我想将照片发布到专辑“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

1 个答案:

答案 0 :(得分: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
)

这应该至少可以为您提供有关正在发生的事情的线索。