Asked  7 Months ago    Answers:  5   Viewed   45 times

Now I posting a single photo to 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',
   )
);

It works fine, but can I somehow post a multiple photos, something like this:

enter image description here

 Answers

52

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

Wednesday, March 31, 2021
 
SkyNet
answered 7 Months ago
25

The path you are using /406221796071956/photos is wrong and that's why it does not work.

The reason that this path is wrong, is that 406221796071956 is the id of a picture, see for yourself, the Graph API Explorer for 406221796071956 says:

"type": "photo"

If you want to publish to that album then use /196878530339618/photos, since it's the album: Graph API Explorer for 196878530339618

"type": "album"


Edit

Please refer to https://developers.facebook.com/docs/reference/api/album/#photos for adding photos to an album.


2nd Edit

According to the documentation of the Album object:

can_upload

Determines whether the UID can upload to the album and returns true if the user owns the album, the album is not full, and the app can add photos to the album

So you need the album not to be full, to be the owner of the album and have the right permissions for uploading.

Wednesday, March 31, 2021
 
rob_mccann
answered 7 Months ago
24

Figured out the problem. I had a typo... I was assigning the url to $logoutUrl and was trying to get the url from $logout_url...

Thanks

Wednesday, March 31, 2021
 
Wookai
answered 7 Months ago
61
set_time_limit(99999999);
ini_set('memory_limit', "9999M");

function fetchUrl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    
    $data = curl_exec($ch);
    curl_close($ch);
    
    return $data;
}

$url_array = array();

function recurse_it($url, $c) {
    global $url_array;
    $feeds         = fetchUrl($url);
    $feed_data_obj = json_decode($feeds, true);
    if (!empty($feed_data_obj['data'])) {
        $next_url      = $feed_data_obj['paging']['next'];
        $url_array[$c] = $next_url;
        recurse_it($next_url, $c + 1);
    }
    return $url_array;
}

$url = "https://graph.facebook.com/55259308085/groups?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$arr = recurse_it($url, 0);
print_r($arr);

Where $arr is an array of all the available pagination links for which I used a foreach to loop through all the contents of the pagination.

Sunday, August 8, 2021
 
csi
answered 3 Months ago
csi
73

I've verified using the Graph API explorer that the pagination is not working as you have described. Log it as a bug with Facebook at: https://developers.facebook.com/bugs and post the bug # here.

EDIT

Per the bug closure, the 100 limit is By Design and you won't get more than that, meaning that Facebook has made a conscious business decision to limit the amount of data it has to store, process, and serve from the Graph API. It costs money to do so and since the API is free to use, I can't argue with them. However, if I was paying for it, then hell yes I kick and scream all the way down the road.

Saturday, August 14, 2021
 
0skar
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :