1

hello guys im trying to automate a stories video post on facebook but dont know what im doing wrong, my picture stories function works fine but my video one is not working at all!!! i tried to look over here and documentation for a answer but couldnt find a solution! in the first 10 calls i was getting errors from graph and from now on i keep getting erro 500! does anyone knows what i can be doing wrong?

    function postStoriesVideoFacebook($fb, $pageId, $pageAccessToken, $mediaUrls) {
        $mediaUrls = 'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4';
       // Etapa 1: Inicializar a sessão de upload
       $response = $fb->post("/{$pageId}/video_stories", [
        'upload_phase' => 'start',
    ], $pageAccessToken);

    $initData = $response->getDecodedBody();
    $videoId = $initData['video_id'];
    $uploadUrl = $initData['upload_url'];

    // Debugging - Verificando as variáveis
    var_dump($initData, $videoId, $uploadUrl);

    // Etapa 2: Fazer upload do vídeo usando a URL remota
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $uploadUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Authorization: OAuth $pageAccessToken", // Passando o token como OAuth
        "file_url: $mediaUrls"
    ]);


    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $uploadResponse = curl_exec($ch);
    curl_close($ch);

    $uploadData = json_decode($uploadResponse, true);

    // Debugging - Verificando a resposta do upload
    var_dump($uploadData);

    if (isset($uploadData['success']) && $uploadData['success'] === true) {
        // Etapa 3: Publicar o vídeo nos Stories
        $finishResponse = $fb->post("/{$pageId}/video_stories", [
            'upload_phase' => 'finish',
            'video_id' => $videoId,
        ], $pageAccessToken);

        $result = $finishResponse->getDecodedBody();

        // Debugging - Verificando a resposta da publicação
        var_dump($result);

        if (isset($result['success']) && $result['success'] === true) {
            return $result['post_id']; // Retorna o ID do post se a publicação for bem-sucedida
        } else {
            throw new Exception('Erro ao publicar o vídeo nos Stories.');
        }
    } else {
        throw new Exception('Erro ao fazer upload do vídeo.');
    }
}

forums , using direct the cURL options, postman etc

3
  • HTTP 500 -> Have a look into the logfiles. Commented Aug 30 at 6:01
  • Is this the actual media URL you used? If so - I am getting a 404 for that in my browser; do you have any reason to believe Facebook would get a different response?
    – C3roe
    Commented Aug 30 at 6:10
  • the url was valid yesterday, now im using this one but keep getting 500 samplelib.com/lib/preview/mp4/sample-5s.mp4 Commented Aug 30 at 11:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.