Posts tagged with facebook-graph-api

I am trying to automate posting to Facebook using the Facebook Node.js SDK. However, for testing purposes, I thought of trying first from the Facebook Graph Explorer API UI. I was following the steps from the docs here: https://developers.facebook.com/docs/pages-api/getting-started/. I added all the permissions but am getting this error when I try posting to https://graph.facebook.com/v20.0/page_id/feed. Here is the error:

{   "error": {     "message": "(#200) If posting to a group, requires app being installed in the group, and \           either publish_to_groups permission with user token, or both pages_read_engagement \           and pages_manage_posts permission with page token; If posting to a page, \           requires both pages_read_engagement and pages_manage_posts as an admin with \           sufficient administrative permission",     "type": "OAuthException",     "code": 200,     "fbtrace_id": "AvqEpJBCdYALhe1DcGEMOee"   } } 

Here are the scopes:pages_show_list, pages_read_engagement, pages_manage_metadata, pages_manage_posts, public_profile.Idont know where the problem is because i have added all the permission needed.

I expected somrthing like this as per the documentation. { "id": "page_post_id" }

I am currently using facebook-nodejs-business-sdk:"^18.0.0" graph api for Insights.

I have below piece of code in map which returns array of Api requests. Using the the instance of FacebookAdsApiBatch i am putting each request into it which should return multiple results as it batch

return new APIRequest(    `http://graph.facebook.com/v18.0/${levelId}`    'GET',    'insights' )  .addParam('access_token', XX_X_X)  .addParam('fields', 'impression, clicks')  .addParam('level', levelType) 

Above Array of APIRequest passed in below fucntion

async getBatchRequestResult(requests: APIRequest[]): Promise<any> {   const batchApi = new FacebookAdsApiBatch(      getFbApiInstance(),      (res) =>{         console.log('batch instance success ', res)      },      (error) => {         console.log('batch instance error', error)      }   )   reqests.forEach((request) => {      batchApi.addRequest(         request,          (data) => {           console.log(' Success addRequest: ${JSON.stringify(data)}')          },         (error) => {           console.log('error', error)         }      )   })   return new Promise((resolve, reject) => {       batchApi         .execute()         .then((responses) => {            console.log('***RESPONSES****', responses);            resolve(responses)         })         .catch((error) => {            console.log('***ERROR****', error);            reject(error)         })         }) } 

Current in lambda logs I am seeing 3 types of logs in order.

  1. batch instance success: { kind of same json as below }
  2. Muliple "Success addRequest" logs. One of mentioned below Success addRequest:
{  "_body": {     "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights"   }  "status": 200,  "_headers": [     long list of objects   ],  "_call": {     "method": "GET",     "relative_url": "https://graph.facebook.com/v18.0/<CAMPAIGN_ID>/insights?                         access_token=XX_X_X                        &**fields**=&level=campaign"     "attachedFiles": ""      }     .......     .......   } } 
  1. RESPONSES = Null

Question is, If we pay attention on relative_url the fields value is empty despite the fact I am passing string 'impression, clicks'. I tried with array ["impression", "clicks"] and addParams({ key:Val }) but it still not passing that value. Really not sure why it is ommitting. All other parameters are fine. I doubt that this is the why I am facing issue of Null as final result. fields is important for me because I have to fetch tons of other measures as well.

Can someone please help me to figure out what is the issue? If anyone need further detail I am ready to give as much I can.

Currently in codebase we have "new Campaign" instance which has getInsights(null, query) fun which working fine. I am replacing this and trying batch call to avoid timeout error from FB for all kind of insights (campaign, adsets, ad) and therir breakdowns and mesures. By achiveing above batch call, the number of API calling to FB would be significantly reduced.

Reference: https://www.npmjs.com/package/facebook-nodejs-business-sdk?activeTab=code ^ Go under BatchExample.js

I am using the Facebook Ads connector in AWS AppFlow to transfer Facebook Ads data. While I can successfully transfer all data objects, the data for ads is being accumulated over the entire lifetime of the ads rather than on a daily basis.

For instance, when generating reports using Facebook's Graph API, I retrieve daily data as follows:

https://graph.facebook.com/{ad_id}/insights?fields={field_names}&time_range={'since':'2021-08-19','until':'2021-08-20'} https://graph.facebook.com/{ad_id}/insights?fields={field_names}&time_range={'since':'2021-08-20','until':'2021-08-21'} https://graph.facebook.com/{ad_id}/insights?fields={field_names}&time_range={'since':'2021-08-21','until':'2021-08-22'} 

I would like to achieve the same daily data transfer using AWS AppFlow for the entire duration the ad has been running. How can I configure AWS AppFlow to transfer the ads data on a daily basis instead of the accumulated data over the ad's lifetime? Any guidance or examples would be greatly appreciated.

I have got the following data transferred for the lifetime of ad run between 2021-08-17 and 2024-06-05

{"account_currency":"USD","account_id":"","account_name":"","actions":[{"action_type":"onsite_conversion.post_save","value":"7"},{"action_type":"comment","value":"10"},{"action_type":"link_click","value":"433"},{"action_type":"post","value":"39"},{"action_type":"like","value":"3969"},{"action_type":"post_reaction","value":"2847"},{"action_type":"page_engagement","value":"7305"},{"action_type":"post_engagement","value":"3336"}],"ad_id":"","ad_name":"","adset_id":"","adset_name":"","buying_type":"AUCTION","campaign_id":"","campaign_name":"","clicks":"8000", "date_start":"2021-08-17","date_stop":"2024-06-05" 

What I need is a daily level data transfer for all the days between 2021-08-17 and 2024-06-05 i.e, for all the days the ad has run.

I am using /ads_archive docs search endpoint to search for Facebook archived ads. It returns data in JSON format. Easy to parse and to work with. However, it only contains short info about Ad.

More detailed info is under ad_snapshot_url of format https://www.facebook.com/ads/archive/render_ad/?id={AD_ID}&access_token={ACCESS_TOKEN}. You need to go to this URL and parse HTML, which is very uncomfortable. Info is stored inside javascript objects. Not easy to work with.

Is there any Facebook API alternative for ad_snapshot_url that returns data in JSON format?

Tried to put Accept-Language: application/json into request headers. Tried different formats like: https://graph.facebook.com/v19.0/ads_archive/{AD_ID} https://graph.facebook.com/v19.0/ads_archive/ad/{AD_ID} https://graph.facebook.com/v19.0/ads_archive/details/{AD_ID}

No luck.