Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Can we post multiple photos in a single update using Facebook API with JS SDK

I am trying to get multiple images from the user and post it on the Facebook page using Facebook Graph API Javascript SDK. Currently, I am able to post a single image. I searched facebook documentation and got nothing except it may be possible through albums, batch requests, or adding an unpublished post and then publishing it. But I don't know about any of them exactly. Your help will be highly appreciated. Following is the code used to publish a single image:

function postImage()
{

    $uploadDirectory = "uploadedFiles/";
    $filename = $_FILES["postImage"]["name"];
    $extension = pathinfo($filename, PATHINFO_EXTENSION);
    $uniqueName = uniqid("UP-IMG-", true) . "." . $extension;
    $destinationPath = $uploadDirectory . $uniqueName;
    move_uploaded_file($_FILES["postImage"]["tmp_name"], $destinationPath);
    $_GET['imageUrl'] = "https://www.salebazarmzd.com/" . $destinationPath;

    //creating variables to store data from Super Global Vars
    $url = $_GET['imageUrl'];
    $message = $_POST['postDescription'];
    $link = $_POST['postLink'];
    $message = $message . "\n" . $link;
    $page_access_token = $_GET['page_access_token'];
    $page_id = $_GET['page_id'];
    echo $url;
    echo $message;
    $script = <<< JS
                        $(function() {
                            var form = document.querySelector('#form');
                            const data = Object.fromEntries(new FormData(form).entries());
                            console.log(data['postImage']);
                            var formData = {
                                "message": `$message`,
                                "url": "$url",
                                'access_token': "$page_access_token"
                            }
                            console.log(formData);
                            FB.api(
                                '/$page_id/photos',
                                'POST',
                                formData,
                                function(response) {
                                    console.log(response);
                                }

                            )
                            
                        });
                        JS;
    return $script;
}

I have used PHP to get the file and store it on the server and then sent the request using FB.api() which is available through Facebook Graph API JavaScript SDK.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!