Posts tagged with facebook-graph-api

I would like to call for suggestions regarding a challenge I've been trying to solve recently involving Meta API & Webhooks. I assume this particular setting has not been addressed here before.

As one may know, to configure receiving requests from WhatsApp, Facebook, and Instagram for a Meta app you need setting up a webhook for each in the respective parts of Meta dev dashboard. This involves allowing webhooks required app-level subscriptions/permissions and providing an endpoint that you confirm by returning a verify token on a GET request to ensure it's ok to send you requests there.

In my case, I would like other people to use the app as well, so I added oath2 to get necessary permissions for user business pages on Wa, Fb or Instagram, which works well.

After that, with necessary access, you can add your or someone's page to a pre-configured webhook, so it starts accepting requests. This action can be done through a dashboard in the menu that looks similar to this depending on the platform.

On the other hand, this can be done with sending a request, specifying webhook subscription fields yourself (such as messages on the picture above).

POST /v20.0/{app-id}/subscriptions HTTP/1.1

However, this feature is only available for Facebook pages and in the request-dedicated article we can see it mentioned. Any other webhook-related requests actually allowed for WhatsApp and Instagram are only for adding a webhook to an app (the very first step described here).

Limitations:

Webhooks for Instagram is not supported. Instagram webhooks must be configured using the App Dashboard. Webhooks for WhatsApp is not supported. WhatsApp webhooks must be configured using the App Dashboard. https://developers.facebook.com/docs/graph-api/reference/v20.0/app/subscriptions

And given that, one needs to do it through dev dashboard UI which is not an acceptable solution in my case.

Therefore, I can really use some insights on how can this be solved directly or through some witty alternative to receive messages from all three platforms and being able to programmatically allow webhook page requests.

Additionally, I have been considering raising the issue with Meta directly, so it can be adjusted and would love to hear thoughts on potentially doing this.

P.S.

For those deeply interested in the issue, I found some sort of similar issue on the meta dev forum https://developers.facebook.com/community/threads/799110895741478/

Summary

I have been trying to publish reels on Instagram using the Instagram API. However, none of my attempts have worked so far.

My setup

  • I'm using an un-audited app on developers.facebook.com
  • I want to publish on an instagram page I own (business account)
  • This page was added to the app as an instagram tester

Documentation used

I have been following this page of the documentation on developers.facebook.com

My process

Step 1: OAuth

This part I did directly from the developer dashboard. The token I got has the following permissions:

  • business_basic
  • business_manage_messages
  • business_content_publish
  • business_manage_comments

Step 2: Create media container

For this part I'm doing just like the documentation says.

def create_instagram_media_container(ig_id: str, video_url: str, access_token: str):     url = f"https://graph.instagram.com/v20.0/{ig_id}/media"     headers = {         "Content-Type": "application/json",     }     data = {         "media_type": "REELS",         "video_url": video_url     }     response = requests.post(url, headers=headers, json=data)     if response.status_code == 200:         return response.json()     else:         response.raise_for_status() 

I am able to get a container ID with this step.

Note: After reading materials online, I have tried a few variations, including adding "Authorization": f"OAuth {access_token}" to the header and "upload_type": "resumable" to the data, but this didn't fixed it.

Step 3: Publish container

Once again, I am following the documentation.

def upload_instagram_video(ig_id: str, ig_container_id: str, access_token: str):     url = f"https://graph.instagram.com/v20.0/{ig_id}/media_publish"     headers = {         "Content-Type": "application/json"     }     data = {         "creation_id": ig_container_id,     }     response = requests.post(url, headers=headers, json=data)     if response.status_code == 200:         return response.json()     else:         response.raise_for_status() 

At this stage however, I get an error.

At first I had the following description:

b'{"error":{"message":"Unsupported post request. Object with ID \'[...]\' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\\/\\/developers.facebook.com\\/docs\\/graph-api","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AKe1_Gl1c5kNSTrKHPYuyHG"}}'

But now I just get a 400 error stating "Sorry, this content isn't available right now".

Note: After reading materials online, I have also tried adding "Authorization": f"OAuth {access_token}" to the header here, but this didn't fixed it.

My thoughts

I have a few ideas as to where the confusion could be comming from, but I didn't really manage to make anything out of them.

  • Endpoints: I am querying the graph.instagram.com endpoint, but there is also a graph.facebook.com. This seemed a bit more complete, as the documentation mentions extra fields like caption, but I didn't manage to make it work either. I think I should still go with the Instagram one as the documentation states that "Unlike the Instagram API with Facebook Login, this API doesn't require a Facebook Page linked to the Instagram professional account." which seems simpler.
  • Token: Reading online, I could see some mentions of a difference between a page token and a user token. I didn't really understand the distinction. I generated my token directly from the "Instagram" tab of the developer website, and there is no such distinction there. From the migration guide I'd guess that it's not applicable in that case since I'm using the Instagram API setup with Instagram Login.

After trying for several days in a row, I am now completely lost. Your help would be greatly appreciated. Thank you!

I’m using the Facebook Ads Archive API to fetch ads with the following URL:

https://graph.facebook.com/v11.0/ads_archive?access_token=MY_ACCESS_TOKEN&search_terms=MY_SEARCH_TERM&ad_reached_countries=AE&fields=ad_creation_time,ad_delivery_start_time,ad_delivery_stop_time,ad_creative_bodies&limit=1000&ad_active_status=ALL

This URL returns ads as expected, but without the active ads. And when I modify the URL to filter only active ads:

https://graph.facebook.com/v11.0/ads_archive?access_token=MY_ACCESS_TOKEN&search_terms=MY_SEARCH_TERM&ad_reached_countries=AE&fields=ad_creation_time,ad_delivery_start_time,ad_delivery_stop_time,ad_creative_bodies&limit=1000&ad_active_status=ACTIVE

I get no data, even though I can see active ads matching this criteria manually in the Ads Library.Could someone please help me understand why this might be happening and how I can resolve it?

I expect to see all the active ads

We developed our own platform to schedule Instagram Posts via the Instagram Graph API.

It's working fine but we can't find a way to add linebreaks to the Reel Description.

We tried to use \n as well as some html tags like <p> but nothing works. It's like after publication, Instagram automatically deletes the spaces and reduces them to one space.

I know it's possible because some scheduling SAAS like Later can schedule Reels with linebreaks in the description.

I'm trying to find someone who solved the problem already. What should I try next? How to format the json?

Thanks, T.

I am able to create new business manager using graph api exploror by using below api

POST https://graph.facebook.com/v20.0/{user-id}/businesses {"name":"","vertical":""} 

I am trying to do same by using system-user-access-token which has business_management permission still i always end-up with An unknown error has occurred

{     "error": {         "message": "An unknown error has occurred.",         "type": "OAuthException",         "code": 1,         "fbtrace_id": "AJLLEHScJ2XZs2Zfc6LSiOP"     } } 

Is there any way to create business manager using system-user access-token