How do I can post a multiple photos via Facebook API

前端 未结 5 1963
难免孤独
难免孤独 2020-11-29 10:26

Now I posting a single photo to wall like this:

$response = $facebook->api(\"/$group_id/photos\", \"POST\", array(
    \'access_token=\' => $access_to         


        
5条回答
  •  没有蜡笔的小新
    2020-11-29 11:05

    You can make batch requests as mentioned here: https://stackoverflow.com/a/11025457/1343690

    But its simple to loop through your images and publish them directly.

    foreach($photos as $photo)
    {
           //publish photo
    }
    


    Edit:

    (regarding grouping of photos on wall)

    This grouping is done by facebook automatically if some photos are uploaded into the same album.

    Currently you cannot create an album in a group via Graph API - it is not supported (as of now), see this bug.

    But you can do this - create an album manually, then get the album_id by-
    \GET /{group-id}/albums, then use the the code with album_id instead of group_id-

    foreach($photos as $photo){
       $facebook->api("/{album-id}/photos", "POST", array(
          'access_token=' => $access_token,
          'name' => 'This is a test message',
          'url' => $photo
          )
       );
    }
    

    I've tested it, see the result-

    enter image description here

提交回复
热议问题