How do I can post a multiple photos via Facebook API
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-
Facebook graph api page post with multiple photos
TL;DR
Add publish_to_groups permission to the access token and the request for the post should be with parameter published: true. It appears to have a bug in the graph api or lack of information in the official docs.
Details:
Currently in order to publish a page post with multiple photos you will need to:
- upload individually the photos and obtain their IDs
- use PAGE access token which contains publish_to_groups permission
- attach all photo IDs with attached_media[0..N]: {"media_fbid": "PHOTO_ID"}
- currently the request for publishing the post fails if it's with parameter published: false, so it needs to be published: true
All of this does not make really sense to me, so I opened a bug report in the developers platform of Facebook. It does not looks right during development of the App to publish live posts to the page...
I'll edit the answer once I have a feedback.
Create multi-photo post on Facebook page using Graph API 7.0 or newer
It is impossible to create a new album via Graph API as of v7.0+. What can be done instead, is to upload multiple pictures to the page in unpublished state using POST /page-id/photos
and then creating a feed story with the unpublished pictures as attachments, using POST /page-id/feed
. This workflow, with examples, is explained in detail here: https://developers.facebook.com/docs/graph-api/photo-uploads/
Facebook Graph API publish post with multiple attachments
As of now it is not possible to publish one post with multiple pictures. You need to create separate posts for each one of them, or put all the images together in one with your favourite server language and post it as single picture.
Related Topics
Php/Regex: How to Get the String Value of HTML Tag
Any Way to Specify Optional Parameter Values in PHP
Remove Index.PHP in Codeigniter 2.1.0
How to Include Authorization Header in Curl Post Http Request in PHP
Exotic Names for Methods, Constants, Variables and Fields - Bug or Feature
How to Kill A/All PHP Sessions
Binding Params for Pdo Statement Inside a Loop
Why Is Crontab Not Executing My PHP Script
Replace String in Text File Using PHP
Call to Undefined Function Apache_Request_Headers()
How to Fetch Associative Array Grouped by the Values of a Specified Column with Pdo
Is My Understanding of PHP Sessions Correct
String Contains Any Items in an Array (Case Insensitive)
How Get All Values in a Column Using PHP
How to Execute Stored Procedure from Laravel
What Is the Best Practice to Export Canvas with High Quality Images
Concatenating a String and Primary Key Id While Inserting
How to Use Single Quote Inside an Echo Which Is Using Single Quote