A
A
Andrey2014-04-11 20:44:10
PHP
Andrey, 2014-04-11 20:44:10

How to post multiple photos in one post using the Facebook API?

Hello colleagues!
At the moment I'm posting pictures on the wall like this:

$response = $facebook->api("/$group_id/photos", "POST", array(
    'access_token=' => $access_token,
    'message' => 'This is a test message',
    'url' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
   )
);

Everything works fine, but I would like to know how you can post several pictures at once? Something like this:
0761e795eadd4680b12ee6cd52756462.jpg
The advice on stackoverflow is to just post each picture with a separate API call, and Facebook should automatically merge those pictures into a single post (if the interval between them is less than a minute), but in practice this does not happen. Tell me, please, how can this be done?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey, 2014-04-12
@RedOctoberCZ

In general, to post several photos to a group, you need to create an album in the group. It is impossible to create an album in a group using the API, and this is a known bug , but they are in no hurry to fix it :)

A
Alexander Lapenko, 2016-06-21
@webrider

In general, yes.
In order to make a post with multiple photos, you need to do the following:

$fb = new Facebook\Facebook([
      'app_id'  => $app_id,
      'app_secret' => $app_secret,
      'default_graph_version' => 'v2.4',
    ]);
$images = ['http://site.ru/img1.jpg', 'http://site.ru/img2.jpg', 'http://site.ru/img3.jpg'];
$token = 'ВАШ ТОКЕН';
$group_id = 'ID группы';
$attached['message'] = 'Текст поста'; 
$i = 0;

foreach ($images as $image) { 
$response = $fb->post('/me/photos', [
  'url' => $image,
   'published' => 'false' #Дабы они не появлялись на стене
], $token);
$graphNode = $response->getGraphNode();
 $attached['attached_media[' . $i . ']'] = '{"media_fbid":"' . $graphNode['id'] . '"}';
$i++;
}
#Далее, собственно, сам пост
$response = $fb->post("/{$group_id}/feed", $attached, $token);

All the best

Y
Yaroslav Nikitin, 2014-04-11
@copyloc

And an array of multiple URLs? I'm not sure, just my guess. Something like:

$str = "ссыль1,ссыль2,ссыль3"; 
  $url = explode(",",$str);

And then pull out the form:
for($i = 0; $i < count($url); $i++) 
  { 
     echo $url[$i]." "; 
  }

And get enumeration of links

B
barabylia, 2015-03-07
@barabylia

you post three posts at once with different photos and the same text, then a stack of photos comes out (tested for the user, it doesn’t seem to work for the page).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question