Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda