Posts tagged with facebook-graph-api

Im trying to get all the comments of the posts, im using the after and before things of the cursor in Facebook graph, but it does not give me all comments.

const fetchAllPostComments = async (postId: string, after: string | null = null, limit: number = 25): Promise<any[]> => {     const pageQuery = after ? `&after=${after}&limit=${limit}` : `&limit=${limit}`;     const response = await fetch(`${GRAPH_API_URL}/${postId}/comments?access_token=${PAGE_ACCESS_TOKEN}${pageQuery}`);     const data = await response.json();     let allComments = data.data || [];     if (data.paging && data.paging.cursors && data.paging.cursors.after) {         const nextComments = await fetchAllPostComments(postId, data.paging.cursors.after, limit);         allComments = allComments.concat(nextComments);     }     console.log(allComments);     return allComments; }; 

I use facebook graph api in my app and I faced some issues I cannot crack for a while. Unfortunately their documentation is not always clear, so I would appreciate any tips on my questions. My app is build in Next.js, but I don't think language matters here.

1.Upload video trouble.

I follow this documentation. https://developers.facebook.com/docs/video-api/guides/publishing Publish video on the page takes three steps. 1.1 Start an upload session. I use here my business app Id and my test user account for user access token

 curl -i -X POST "https://graph.facebook.com/v20.0/<APP_ID>/uploads  ?file_name=<FILE_NAME>  &file_length=<FILE_LENGTH>  &file_type=<FILE_TYPE>  &access_token=<USER_ACCESS_TOKEN>" 

I get successfull return

{   "id": "upload:<UPLOAD_SESSION_ID>" } 

1.2. Start upload session. Same user token as in the first call and upload session Id which I received in the first response. Currently I test in Postman, so no issues yet converting video file, just file attached type video/mp4.

 curl -i -X POST "https://graph.facebook.com/v20.0/upload:<UPLOAD_SESSION_ID>"   --header "Authorization: OAuth <USER_ACCESS_TOKEN>"   --header "file_offset: 0"   --data-binary @<FILE_NAME> 

Success. Receive file handle response

{    "h": "2:c2FtcGxl..." } 

1.3. Publish video. And here is an error

 curl -X POST \   "https://graph-video.facebook.com/v20.0/<PAGE_ID>/videos" \   -F "access_token=<PAGE_ACCESS_TOKEN>" \   -F "title=<VIDEO_TITLE>" \   -F "description=<VIDEO_DESCRIPTION>" \    -F "fbuploader_video_file_chunk=<UPLOADED_FILE_HANDLE>" 

Page Id I use Page from my test user account, page token from this page. Handle - response from previous step. It end up in response:

{    "error": {       "message": "(#100) Using file handle created for another user",       "type": "OAuthException",       "code": 100,       "fbtrace_id": "AOF82skhP9OWC_yFlh_ka4q"    }  } 

Question? For whom did they create a handle?? Which another user? I use page credentials which belong to the user, whom user_token I used in the first steps. I follow all official documentation with headers, I insert user token in the header in the second step, as required, but I always end up with this error. Any ideas what potentially can go wrong?

2.Post Page insights for analytics.

I get analytics for page following this documentation https://developers.facebook.com/docs/graph-api/reference/v20.0/insights

For example call

  GET v20.0/{Page_Id}/insights?metric=page_post_engagements,page_daily_follows&period=week&since=01.09.2024&untill=30.09.2024 

There are three options for most of metrics - day, week and days_28. What is not clear for me, its's how to combine it with 'since' and 'untill'? I have an interactive page, where user can dynamically select 'period', 'since' and 'untill with datePicker, It always shows different data and I'm not sure what exactly I display.. for the call

 page_id/insights?metric=page_post_engagements&since=01.09.2024 

I will receive data for day, week, and day_28, per day since selected date till today. But data for the same day in each of there three sections will differ. What does this data represent? Example response:

 "name": "page_post_engagements",   "period": "day",   "values": [     {       "value": 0,       "end_time": "2024-09-02T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-03T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-04T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-05T07:00:00+0000"     },     {       "value": 9,       "end_time": "2024-09-06T07:00:00+0000"     },     {       "value": 4,       "end_time": "2024-09-07T07:00:00+0000"     }, }, {   "name": "page_post_engagements",   "period": "week",   "values": [     {       "value": 0,       "end_time": "2024-09-02T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-03T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-04T07:00:00+0000"     },     {       "value": 0,       "end_time": "2024-09-05T07:00:00+0000"     },     {       "value": 9,       "end_time": "2024-09-06T07:00:00+0000"     },     {       "value": 13,       "end_time": "2024-09-07T07:00:00+0000"     }, }, {   "name": "page_post_engagements",   "period": "days_28",   "values": [     {       "value": 5,       "end_time": "2024-09-02T07:00:00+0000"     },     {       "value": 5,       "end_time": "2024-09-03T07:00:00+0000"     },     {       "value": 5,       "end_time": "2024-09-04T07:00:00+0000"     },     {       "value": 5,       "end_time": "2024-09-05T07:00:00+0000"     },     {       "value": 14,       "end_time": "2024-09-06T07:00:00+0000"     },     {       "value": 18,       "end_time": "2024-09-07T07:00:00+0000"     }, 

Can someone explain me please? If I want, for example, display : "Your page activity this week increased/dropped for 15% compare to last week", how do I need to set my search params?

Thanks everyone for any ideas

We are integrating WhatsApp Cloud API for our app through the Business API Gateway. Here's what we have done so far:

Successfully generated a short-lived access token via the Graph API. Used the token, version, and ID for API calls, which worked fine. Meta approved our app review request. However, the issue arises when we attempt to generate a long-lived (or permanent) access token. After making the request, our account gets temporarily blocked or restricted.

Does anyone know why this might be happening or what steps we need to take to avoid the restriction when generating a long-lived access token?

We're following Meta's guidelines for generating access tokens. Short-lived tokens work fine, but the issue is specific to the long-lived token generation. We've made sure all API calls adhere to the required permissions and scopes. Any guidance or insights would be appreciated.

I am creating a web app which uses Facebook graph apis to allow users connect their Facebook and Instagram account to my app so we could automate content posting on their behalf. I have successfully implementend for Facebook but the problem is now with Instagram. After I initiate the auth url I am taken to a page where I'm asked to enter my IG email and password, a popup opens and I enter those details but it doesn't get past there, it just goes back to telling me to "Get started" which is where I started from.

I have been strugling with this problem for days now and would greatly appreciate any help I could get with this.

Another guess I have: Though I doubt that is the case but could this be happening because I am yet to submit my app for review? If so, why did it work for Facebook?

What I have tried:

  1. I have added and double checked my redirect_uri both on my website and my Facebook developers App
  2. Checked if this issue persists across multiple browsers

What I expect: After entering my instagram username and password, I should be redirected to my redirect_uri with the access_token and other requested information so I can process them