Posts under category Facebook Graph API

I'm currently migrating an app that uses the Instagram Basic Display API (api.instagram.com) to the Instagram Graph API (graph.instagram.com), as the Basic Display API will be deprecated on December 4th, 2024.

I’ve read in the official documentation that I need to create a new app of type "Business" in Meta for Developers and request the instagram_business_basic scope to perform the same actions as before.

Current Implementation

For token generation and API calls, my current workflow looks like this:

1. Short-Lived Access Token Generation

// Short-lived token $url = "https://api.instagram.com/oauth/access_token"; $fields = array(   'client_id' => MY_APP_ID,   'client_secret' => MY_APP_SECRET,   'grant_type' => 'authorization_code',   'redirect_uri' => MY_REDIRECT_URI,   'code' => $code ); return call_curl("POST", $url, $fields); 

2. Long-Lived Access Token Exchange

// Long-lived token $url = "https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=" . MY_APP_SECRET . "&access_token={$token}"; return call_curl("GET", $url); 

3. API Calls

$data = fetchData("https://graph.instagram.com/me/media?fields={$fields}&access_token={$tokenInstagram}"); 

My Concerns

  • The short-lived token generation process appears to still use the endpoint https://api.instagram.com/oauth/access_token. Is this endpoint going to stop working after the Basic Display API deprecation?
  • Although I’ve switched to the Instagram Graph API for token exchange (graph.instagram.com/access_token) and data fetching, I’m worried that the short-lived token endpoint dependency will cause issues post-deprecation.
  • The Graph API Explorer doesn’t list the graph.instagram.com endpoint, and most references online seem to use graph.facebook.com. Should I be using graph.facebook.com instead for Instagram-related API calls?

What I’ve Done So Far

  • I’ve created a new Business-type app in Meta for Developers.
  • I’ve configured the app with the necessary Instagram permissions.
  • The app has been reviewed and approved by Meta.
  • I’ve verified the generated tokens using the Token Debugger tool, and they are associated with the correct Business app.

My Question

Despite these steps, I’m still unsure if my implementation is fully future-proof for the Instagram Graph API.

  1. Am I missing any critical steps or considerations here?
  2. Should I be worried about the short-lived token generation endpoint?
  3. Why isn’t graph.instagram.com listed in the Graph API Explorer, and should I switch to graph.facebook.com for Instagram API calls?

Any guidance or clarification would be greatly appreciated!

My app is registered on facebook and has been live since the past 2 years. Now, i switched it to development mode since i need to integrate with "Instagram API with Facebook login".

So after following the documentation, https://developers.facebook.com/docs/instagram-platform/instagram-api-with-facebook-login/business-login-for-instagram , i linked my insta business account to one of my facebook pages using this link https://www.facebook.com/business/help/connect-instagram-to-page (Note : My facebook account has 2 pages)

I also linked the fb account to insta account by following this : https://help.instagram.com/176235449218188

I have added instagram under products section in my registered app in facebook. I have not confgured anything with respect to "API Setup with facebook login" there.

Now, iam trying to access /me/accounts to get all the pages data and instagram business account id by including scopes "instagram_basic" and "instagram_content_publish"

But iam not getting any data in graph API tool. It just returns

{   "data": [   ] } 

I have tried to debug, but couldnt figure it out. Iam stuck at this point. Any help would be appreciated,thanks.

Can not upload video file node.js to facebook graph api version v21,0 and error is video file not supported

I am Creating a ecommerce what will be able to post facebook the video events of the website .

and I am using facebook graph api version v21.0

for generating session id , I use

//FACEBOOK_GRAPH_API=https://graph.facebook.com //FACEBOOK_GRAPH_VERSION=v21.0 async function initInializeVideoUploadSession({file_name,file_length,file_type,access_token}) {     let url =makeUrlWithParams(`${FACEBOOK_GRAPH_API}/${FACEBOOK_GRAPH_VERSION}/${FACEBOOK_APP_ID}/uploads`,{         file_name,         file_length,         file_type,         access_token     });     log({url})     let res=await fetch(url, {         method :'POST'     });     res=await res.json();     if (!res.id) {         console.log(res);         throw 'Can not facebook token'     }     return res.id } 

for generating the file handle

 //FACEBOOK_GRAPH_API=https://graph.facebook.com //FACEBOOK_GRAPH_VERSION=v21.0 async function uploadAVideoFile(options) {     let prom= new Promise( async(resolve, reject) => {         let {             session,             access_token,             videoPath,             filename         }=options         let url =makeUrlWithParams(`${FACEBOOK_GRAPH_API}/${FACEBOOK_GRAPH_VERSION}/${session}`,{})         log({url})         request(url , {             method :'POST',              headers :{                 'Authorization':'OAuth '+access_token,                 'file_offset' :'0',                 'accapt':"video/mp4",                 'cache-control': 'no-cache',                 'content-type' : 'video/mp4',                 'content-disposition': 'attachment; filename=' + filename,                 'content-length':fs.statSync(videoPath).size.toString()             },             body :fs.readFileSync(videoPath,'binary'),             encoding :null         },responseCallBack)         function responseCallBack(error , response, data) {             data=JSON.parse(data);             log(data)             if (data.h) return resolve(data.h)             if (!data.h) {                 throw new Error('File Handler is not define')             }         }     })     let h=await prom.then(h => h)     return h    } 

By facebook api, I can generate session id ,file handle ,

but when I am using this file handle to post a video on facebook page i am getting error ,video format not supported,please see the upload video code

 async function videoFacebookApi(req,res) {     let {title,description,filename}=req.body;       try {         if (typeof title        !==  'string' ) throw 'title is null'         if (typeof description  !==  'string' ) throw 'description is null'         if (typeof filename     !==  'string' ) throw 'filename is null'         let access_token = await settingsAsString('fb_access_token');         let tokenDate    = await settingsAsString('fb_access_token_enroll_date');         if ( !access_token || !tokenDate) {             throw new Error('!FV_PAGE_ACCESS_TOKEN || !tokenDate')         }         updateFacebookApiAccessToken(tokenDate);         let videoPath=resolve(dirname(fileURLToPath(import.meta.url)), '../../../public/video/Beauty.mp4');                          log('// file upload session started')         let session=await initInializeVideoUploadSession({             file_name:filename,             file_length:fs.statSync(videoPath).size,             file_type:"video/mp4",             access_token         });         log('// file uploading started')         let file_handle= await uploadAVideoFile({             session,             access_token,             videoPath,             filename,             });         log('// video post started')         await request.post(makeUrlWithParams('https://graph-video.facebook.com'+'/'+FACEBOOK_GRAPH_VERSION+'/'+FB_PAGE_ID+'/videos',{}),             {             headers :{                 "Content-Type": "multipart/form-data",                 "accept": "*/*"             },             formData :{                 title,                 description,                 access_token,                 fbuploader_video_file_chunk:file_handle             }         }, uploadToFacebook );         async function uploadToFacebook(error, response, body) {             try {                     if (error) {                     console.error(error)                     return res.sendStatus(500)                 }                 if (body) {                     body=await JSON.parse(body)                     if (body.id) {                         console.log({body});                         console.log('//video upload completed');                                                  return res.sendStatus(201)                     }                     if (body.error) {                         console.error({...body.error});                         return res.sendStatus(400)                     }                     console.log({body});                     return res.sendStatus(200)                 }                 return res.sendStatus(200)             } catch (error) {                 console.log({error});                 return res.sendStatus(500)             }           }     } catch (error) {         log({error})         return res.sendStatus(500)     } } 

Please see the error carefully

{   message: "The video file you selected is in a format that we don't support.",   type: 'OAuthException',   code: 352,   error_subcode: 1363024,   is_transient: false,   error_user_title: 'Unsupported Video Format',   error_user_msg: "The video you're trying to upload is in a format that isn't supported. Please try again with a video in a supported format.",    fbtrace_id: 'ASMNMrVVh4jeY06_nDP_y9d' } 

then docomentation I am following for this functionality is facebook graph api docomentation

I'm using the Instagram Graph API via https://graph.facebook.com/v21.0 to publish both images and videos on Instagram. Publishing images works without issues, but I'm encountering a problem when attempting to publish videos.

Here’s my process:

1. Create Media Container for Video

I create a media container using the following request:

POST https://graph.facebook.com/v21.0/<user-id>/media {    video_url: video.mp4 (744k, 18s long H264 MPEG-4 AAC)    caption: caption    media_type: REELS    share_to_feed: true    access_token: ... } 

2. Publish Media Using the Container ID Then, I attempt to publish the video with this request:

POST https://graph.facebook.com/v21.0/<user-id>/media {     creation_id: <id-container>     access_token: ... } 

However, this returns a 500 error:

{     "error": {         "message": "An unknown error has occurred.",         "type": "OAuthException",         "code": 1,         "fbtrace_id": <trace-id>     } } 

I can't find anything on the community forum and the bug report is not working either. Any idea what I could try?