How do I can post a multiple photos via Facebook API

前端 未结 5 1943
难免孤独
难免孤独 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 10:54

    There is no way to publish more than one photo in the same graph API call.

    See documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-29 11:05

    Actually you can upload a multi story photo(I did it using Graph Api and PHP) but the problem comes if you need scheduled this post.Your post is schedule but also it shows on the page's feed.

    P.S. I'm using Graph Api v2.9

    PHP Code

    $endpoint = "/".$page_id."/photos";
    
    foreach ($multiple_photos as $file_url):
    array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
    endforeach;
    
    $uploaded_photos = $fb->sendBatchRequest($photos,  $page_access_token); 
    
    foreach ($uploaded_photos as $photo):
    array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
    endforeach;
    
    $data_post['message'] = $linkData['caption'];
    
    $data_post['published'] = FALSE;
    
    $data_post['scheduled_publish_time'] = $scheduled_publish_time;
    
    $response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
    
    $post_id = $cresponse->getGraphNode()['id'];
    
    0 讨论(0)
  • 2020-11-29 11:06

    You will need to upload each photo first with published state to false, and then use the ID's of the unpublished photos to the /me/feed endpoint to schedule the photo. The schedule needs to be within the 24 hours from the time the photos are uploaded as facebook deletes all unpublished photos in 24 hours.

    Ref: https://developers.facebook.com/docs/graph-api/photo-uploads/

    0 讨论(0)
  • 2020-11-29 11:09

    You can now publish multiple images in a single post to your feed or page:

    For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false.

    You'll get an ID for each photo you upload like this:

    {
      "id": "10153677042736789"
    }
    

    Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo

     $response = $facebook->api("/me/feed", 'POST',
      array(
        'access_token=' => $access_token,
        'message' => 'Testing multi-photo post!',
        'attached_media[0]' => '{"media_fbid":"1002088839996"}',
        'attached_media[1]' => '{"media_fbid":"1002088840149"}'
      )
    );
    

    Source: Publishing a multi-photo story

    0 讨论(0)
提交回复
热议问题