Interrupción parcialshare-external
Resumable Upload Fails For Carousel and Reels, Works For Stories
1

I am having an issue upload media locally for carousels and reals with resumable uploads. Here is my code for creating the session:

async function createResumableUploadSession(accessToken, instagramAccountId, mediaType) {
  try {

    const payload = {
      media_type: (mediaType === 'CAROUSEL') ? 'VIDEO' : mediaType,
      upload_type: 'resumable',
      access_token: accessToken,
    };

    if (mediaType === 'CAROUSEL') {
      payload['is_carousel_item'] = true;
    }

    const response = await axios.post(
      `https://graph.facebook.com/v20.0/${instagramAccountId}/media`,
      payload
      ,
      {
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'Content-Type': 'application/json',
        },
      }
    );
    return response.data;
  } catch (error) {
    console.error('Error creating resumable upload session:', error.response ? error.response.data : error.message);
    let message = error.response?.data?.debug_info?.message || error.response?.data.error?.message || error.response?.error?.message || error.response?.data?.message || error.message;

    try {
      // Attempt to parse the message as JSON
      const parsedMessage = JSON.parse(message);
      if (parsedMessage && parsedMessage.error && parsedMessage.error.message) {
        message = parsedMessage.error.message;
      }
    } catch (e) {
      // If parsing fails, use the original message
    }

    throw new Error(message);
  }
}

And here is my code for doing the upload:

async function initiateResumableUpload(uploadUri, videoFilePath, accessToken, uploadSessionId, mediaType) {
  try {
    // Read the file into a buffer
    const fileBuffer = fs.readFileSync(videoFilePath);
    const fileSize = fileBuffer.length;

    //uploadUri = `https://rupload.facebook.com/ig-api-upload/{api-version}/{ig-container-id}`;

    const response = await axios.post(
      uploadUri,
      fileBuffer,
      {
        headers: {
          'Authorization': `OAuth ${accessToken}`,
          'offset': '0',
          'file_size' : fileSize
        },
        onUploadProgress: (progressEvent) => {

          const percentageCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total) /3;

          controlWindow.webContents.send('INSTAGRAM_UPLOAD_PROGRESS', { percentage: percentageCompleted, location: videoFilePath });
        },
      }
    );
    return response.data;
  } catch (error) {
      let message = error.response?.data?.debug_info?.message || error.message;
      try {
        // Attempt to parse the message as JSON
        const parsedMessage = JSON.parse(message);
        if (parsedMessage && parsedMessage.error && parsedMessage.error.message) {
          message = parsedMessage.error.message;
        }
      } catch (e) {
        // If parsing fails, use the original message
      }
      console.error('Error uploading video:', message);
      throw new Error(message);
  }
}

This function controls the flow between those two functions:

// Step 1: Create a resumable upload session
    const sessionResponse = await createResumableUploadSession(accessToken, instagramAccountId, mediaType);
    if (sessionResponse.error) throw new Error(sessionResponse.error.message);

    console.log('Session response:', sessionResponse);
    const { id: uploadSessionId, uri: uploadUri } = sessionResponse;

    // Step 2: Upload the video file
    const uploadResult = await initiateResumableUpload(uploadUri, videoFilePath, accessToken, uploadSessionId, mediaType);
    if (uploadResult.error) throw new Error(uploadResult.error.message);
    console.log("Upload Result:", uploadResult);  

When I do stories, this code works! When I do reels or carousels, I get this error:

Error uploading video: Video process failed with error: Unsupported format: The video format is not supported. Please check spec for supported aspect_ratio format

Any ideas as to why?

Devin
Pregunta realizada hace aproximadamente 4 meses