Answer the question
In order to leave comments, you need to log in
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',
)
);
Answer the question
In order to leave comments, you need to log in
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 :)
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);
And an array of multiple URLs? I'm not sure, just my guess. Something like:
$str = "ссыль1,ссыль2,ссыль3";
$url = explode(",",$str);
for($i = 0; $i < count($url); $i++)
{
echo $url[$i]." ";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question