Posts under category Meta & Facebook

Here are the steps I took to get access_token

// Init FB SDK const loadSdk = () => {     window.fbAsyncInit = function () {         window.FB.init({             appId: "218446344509498",             cookie: true,             xfbml: true,             version: "v19.0",         });     };     if (!document.getElementById("facebook-jssdk")) {         const js = document.createElement("script");         js.id = "facebook-jssdk";         js.src = `https://connect.facebook.net/en_US/sdk.js`;         document.body.appendChild(js);     } }; loadSdk(); 

Then I opened the popup that I need for whatsapp embedded sign up

window.FB.login((response) => {     if (response.authResponse) {         const code = response?.authResponse?.code;         console.log(code)     } }, {     config_id: <config-id>, // configuration ID goes here     response_type: "code",     override_default_response_type: true,     scope: 'business_management, whatsapp_business_management, whatsapp_business_messaging', }) 

When I code the code I retrieved my access_token on the server side using the following API

https://graph.facebook.com/v20.0/oauth/access_token?client_id=<client-id>&client_secret=<client-secret&code=<code-i-previously-retrived> 

This returns me an access token that seems to be working with Meta APIs /me, //owned_whatsapp_business_accounts But it returns empty arrays or objects.

When I do the same thing from Meta explorer (select permissions, generate token, copy that token and use, it works)

I have been trying to solve this since many days and not sure where I am doing the mistake.

I want to generate token with correct permissions (it looks like I am doing it because authentication popup also mentions the permissions I requested), and want to able to fetch information from it not empty array

We are experiencing issues with the Instagram Basic Display API and would appreciate any insight or assistance from the community.
Issue Description. When making a GET request to https://graph.instagram.com/v19.0/me on the Instagram Basic Display API, the error in the attached capture occurs. The HTTP Status Code returns a 500 Internal Server Error. This issue occurred at 21:10 UTC on 8/27/2024 and is still ongoing. Currently, user information cannot be Acquisition.
Also, the application mode is in live mode and public_profile and instagram_graph_user_profile are allowed advanced access.
Has anyone encountered this issue or know of a solution? Any information about possible causes or workarounds would be appreciated. Best regards!

We can see the Delivery field on Facebook's ad placement interface to determine whether the ad is in Active, Learning limited, or Learning status. How can we use the official API to retrieve this field?

I have read the corresponding official documentation. but I couldn't find the corresponding field in it. https://developers.facebook.com/docs/marketing-api/reference/adgroup#overview

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!

Hey guys so im trying to automate the post on intagram in my app using the api graph from facebook, i already got the single post of pictures and videos of reels, stories, and post, got as well a carousel of pictures but im having a lot of problem trying to make works to POST a carousel that contais or just reels (videos) and mixed onde having reels and pictures, most of the time i pass the process of creating the container for the first video or picture (when mixed) but in the second one usully or i get a timeout or a erro from graph that dont specify nothing or it fails to create the 2 container and pass the status finished, if anyone can help me would be much appreciated ! my code below !

 function postOnInstagram($fb, $message, $mediaUrls = [], $isCarrosel = false, $pageAccessToken, $instagramAccountId, $hasVideo = false, $typePost){   $fb->setDefaultAccessToken($pageAccessToken);   try {       switch ($typePost) {           case 'post':               if ($hasVideo) {                   return $isCarrosel                        ? postInstagramMediaCarousel($fb, $instagramAccountId, $message, $mediaUrls)                       : postInstagramSingleVideo($fb, $instagramAccountId, $message, $mediaUrls[0]);               } else {                   return $isCarrosel                        ? postInstagramPhotoCarousel($fb, $instagramAccountId, $message, $mediaUrls)                       : postInstagramSinglePhoto($fb, $instagramAccountId, $message, $mediaUrls[0]);               }           case 'reel':               if (!$hasVideo) {                   throw new Exception("Reels require a video");               }               if ($mediaUrls > 1) {                 return postInstagramMultipleVideos($fb, $instagramAccountId, $message, $mediaUrls);               }               else {                 return postInstagramReel($fb, $instagramAccountId, $message, $mediaUrls[0]);               }           case 'story':               if ($hasVideo) {                   return postInstagramStoryVideo($fb, $instagramAccountId, $message, $mediaUrls[0]);               } elseif (!empty($mediaUrls)) {                   return postInstagramStoryPhoto($fb, $instagramAccountId, $message, $mediaUrls[0]);               } else {                   return postInstagramStoryText($fb, $instagramAccountId, $message);               }           default:               throw new Exception("Invalid post type");       }   } catch (FacebookResponseException $e) {       return 'Graph returned an error: ' . $e->getMessage();   } catch (FacebookSDKException $e) {       return 'Facebook SDK returned an error: ' . $e->getMessage();   } catch (Exception $e) {       return 'General error: ' . $e->getMessage();   } } function postInstagramMediaCarousel($fb, $instagramAccountId, $message, $mediaUrls){     $mediaIds = [];     foreach ($mediaUrls as $mediaUrl) {         sleep(10);         // Detect media type based on URL or other means         $mediaType = (preg_match('/\.(mp4)$/i', $mediaUrl)) ? 'VIDEO' : 'IMAGE';         // Create the media and get the creation ID         $creationId = createMediaInsta($fb, $instagramAccountId, $mediaUrl, $mediaType);         if (!$creationId) {             throw new Exception("Failed to create media: $mediaUrl");         }         // Wait for the media to be ready         if (!waitForMediaToBeReadyInsta($fb, $creationId)) {             throw new Exception("Media is not ready: $creationId");         }         $mediaIds[] = $creationId;     }         // Create carousel with the obtained media IDs     $carouselResponse = $fb->post("/$instagramAccountId/media", [         'caption' => $message,         'media_type' => 'CAROUSEL',         'children' => $mediaIds,     ]);       $carouselCreationId = $carouselResponse->getDecodedBody()['id'];     if (!$carouselCreationId) {         throw new Exception("Failed to create carousel.");     }     // Wait for the carousel to be ready     if (!waitForMediaToBeReadyInsta($fb, $carouselCreationId)) {         throw new Exception("Carousel is not ready: $carouselCreationId");     }     sleep(30);     // Publish the carousel     return publishMedia($fb, $instagramAccountId, $carouselCreationId); } function createMediaInsta($fb, $instagramAccountId, $mediaUrl, $mediaType){     // Configura o payload dependendo do tipo de mídia     $payload = [         'media_type' => $mediaType,         'is_carousel_item' => 'true'     ];     if ($mediaType === 'VIDEO') {         $payload['video_url'] = $mediaUrl;     } else {         $payload['image_url'] = $mediaUrl;     }     $response = $fb->post("/$instagramAccountId/media", $payload);     return $response->getDecodedBody()['id']; } function waitForMediaToBeReadyInsta($fb, $creationId, $timeout = 300, $interval = 10){     $start = time();     do {         sleep($interval);         try {             $response = $fb->get("/$creationId");             $status = $response->getDecodedBody()['status'];         } catch (Exception $e) {             // Log the exception and continue waiting             error_log("Exception: " . $e->getMessage());             return false;         }         if ($status === 'READY') {             return true;         }         if (time() - $start > $timeout) {             error_log("Timeout: Media not ready in time.");             return false;         }     } while (true); } function publishMedia($fb, $instagramAccountId, $creationId){   return $fb->post("/$instagramAccountId/media_publish", [       'creation_id' => $creationId   ])->getDecodedBody(); } 

i tried everything that i could find on docs and net but cant find a solution!