Posts tagged with instagram-graph-api

I Am trying to upload Reels from a business Instagram account for that i already have access token and long lived token.The problem is that whenever i try to publish a reel it gives me "The video file you selected is in a format that we don't support." error code:352 and error_subcode:2207026.I have also converted that video but its saying the same.But I am able to upload a video of "640x480" but not any other resolution like 720x1280 etc. The url of video is aws

I have tried converting video using ffmpeg but it gives me aspect ratio error on 720x1280 whether its 9:16 or 16:9 when i try to upload video of like 1080x1920 it gives me streams error i have also added validation in my uploadReel function and funtion return true but still i am getting video format not supported error

import { Request, Response } from 'express'; import axios from 'axios'; import asyncHandler from '../../../middlewares/asyncHandler'; import ffmpeg from 'fluent-ffmpeg'; import ffmpegInstaller from '@ffmpeg-installer/ffmpeg'; ffmpeg.setFfmpegPath(ffmpegInstaller.path); export const uploadReel = asyncHandler(async (req: Request, res: Response) => {   const { longLivedToken, videoUrl }: any = req.body;   if (!longLivedToken || !videoUrl) {     return res.status(400).json({ error: 'Invalid data' });   }   console.log('Checking video format for:', videoUrl);   // Check if the video has supported codecs (H.264 for video and AAC for audio)   ffmpeg(videoUrl).ffprobe((err, metadata) => {     if (err) {       console.error('Error reading video metadata:', err.message);       return res.status(400).json({ error: 'Unable to check video metadata or invalid file.' });     }     console.log('Video metadata:', JSON.stringify(metadata, null, 2));     const hasValidCodec = metadata.streams.some(       (stream: any) => stream.codec_name === 'h264' && stream.codec_type === 'video'     ) && metadata.streams.some(       (stream: any) => stream.codec_name === 'aac' && stream.codec_type === 'audio'     );     if (!hasValidCodec) {       console.error('Unsupported file format. Expected H.264 video codec and AAC audio codec.');       return res.status(400).json({         error: 'Unsupported file format. Ensure the video is in MP4 format with H.264 video codec and AAC audio codec.',       });     }     console.log('Video format is supported. Proceeding with upload.');     // If format is supported, proceed to upload the video     axios.post(       `https://graph.instagram.com/v20.0/me/media`,       {         media_type: 'REELS',         video_url: videoUrl, // Publicly accessible URL of the video file         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' },       }     )       .then((response) => {         console.log('Reel successfully uploaded:', response.data);         return res.status(200).json({ mediaId: response.data.id });       })       .catch((error) => {         console.error('Error uploading reel:', error.response ? error.response.data : error.message);         return res.status(500).json({ error: 'Failed to upload reel' });       });   }); }); export const publishReel = asyncHandler(async (req: Request, res: Response) => {   const { mediaId, longLivedToken }: any = req.body;   if (!mediaId || !longLivedToken) {     return res.status(400).json({ error: 'Invalid data' });   }   try {     const response = await axios.post(       `https://graph.instagram.com/v20.0/me/media_publish`,       {         creation_id: mediaId,         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' }       }     );     return res.status(200).json({ postId: response.data.id }); // Return post ID   } catch (error) {     console.error('Error publishing image:', error.response ? error.response.data : error.message)}      }); 

enter image description here`

I'm tring to get tagged user in post. Currently I'm fetching user post using Business Discovery and some of the post data is possible to fetch. But for tagged user no information is post.

Is there way or endpoint that I'm just overlooking? or just simply not possible with Business Discovery?

Also if it not possible with Business Discovery I would like to know if there is any other way to do it.

I'm making a request here:

https://graph.facebook.com/v20.0/<ig-hashtag-id>/top_media?user_id=<ig-user-id>&fields=id,caption,media_type,media_url,permalink 

example response:

{     "data": [         {             "id": "17887284382178689",             "caption": "Visual literature of Kalinga's interpretation of nature through geometric patterns. Propylene ink on wood.",             "media_type": "IMAGE",             "media_url": "https://scontent-mnl1-2.cdninstagram.com/v/t51.2885-15/25008622_432606043809405_4524106124818907136_n.jpg?_nc_cat=110&ccb=1-7&_nc_sid=18de74&_nc_ohc=BsfOfjgpxugQ7kNvgGvos4J&_nc_ht=scontent-mnl1-2.cdninstagram.com&edm=APCawUEEAAAA&oh=00_AYDeM3F_FCkCYs9CO2eALcn-1Zc8cXRjDszE9bUIKvWYMA&oe=66E0275E",             "permalink": "https://www.instagram.com/p/Bc6461zHsE7/"         },         {             "id": "17866280464216878",             "caption": "\"Traversing Tabuk City to the sleepy town of Tinglayan is one of the roughest road I'v ever been to. Composed of narrow roads and limited pathways, this road is not for the faint hearted. You need to trust the driver maneuvering the vehicle and hopefully he brings you safely to your destination. .\n\nThe long hours of travel, there are no phone signals, the only thing you need to focus on is the view around you.\" 📸 jpxdavid",             "media_type": "IMAGE",             "media_url": "https://scontent-mnl1-2.cdninstagram.com/v/t51.2885-15/27894116_147572912599336_2290924483260710912_n.jpg?_nc_cat=109&ccb=1-7&_nc_sid=18de74&_nc_ohc=XIrmLk4n-EMQ7kNvgHJqdp5&_nc_ht=scontent-mnl1-2.cdninstagram.com&edm=APCawUEEAAAA&oh=00_AYAAY49IH_uTMezzet35bt6n289oRKLOoAdNT1HijQMBJA&oe=66E0271A",             "permalink": "https://www.instagram.com/p/BfkudLeFQiL/"         }    ] } 

but I want to the location of the photo back. how can I do this? by location I mean the little string that appears above the photo in the feed

I have my own instagram account and i have created an app in meta for my account automation.

Everytime i automate private replying to a DM, i get below error after sometime.

{   "error": {     "message": "The thread owner has archived or deleted this conversation, or the thread does not exist.",     "type": "IGApiException",     "code": 100,     "error_subcode": 2534001,     "fbtrace_id": "AgLmAH4eepLIf1PqLBN3y4J"   } } 

When i reply with a comment, i get this below error.

{   "error": {     "message": "This API call does not support the requested response format",     "type": "OAuthException",     "code": 20,     "error_subcode": 1772111,     "is_transient": false,     "error_user_title": "Create Comment Failed - Spam Detected",     "error_user_msg": "To protect the Instagram community, your comment was flagged as spam and could not be added. Please review your comment's content and try again.",     "fbtrace_id": "Aj9iw77tVvnd-loKZG7ULPy"   } } 

There is no documentation for these error code on https://developers.facebook.com/docs/messenger-platform/error-codes/

  1. My meta app is verified.
  2. I am using long lived access token in api calls.

Everything seems fine, why is instagram blocking my automation? How is same working with manychat?

Intially i found some reference to verify my app to prevent this error. So, i have verified my meta app with meta.

I'm trying to integrate the Direct Messages webhook for Instagram Graph API but I need more information about the Direct Message, more specifically about a Share. For example, when someone sends a Share to the user, I receive this type of webhook:

"message": {     "mid": "aWdfZAG1f....",     "attachments": [{         "type": "share",         "payload": {             "url": "https://lookaside.fbsbx.com/ig_messaging_cdn/...."         }     }] } 

The payload only has the image URL of the post, nothing else.
I need to know at least the user ID/username of the owner of that post (the user who posted it).
Is there a way I can achieve this?

Thanks in advance!