Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda