Facebook API Marketing with UrlFetchApp

Digital Marketing Facebook Marketing API 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I'm trying to get my campaign's performance into a Google Spreadsheet. I've written this code function myFunction() { var url = "https://graph.facebook.com/v4.0/CAMPAIGNID/insights" var params = { 'access_token':'MYTOKEN', } var options = { 'method' : 'get', 'payload' : params } var response = UrlFetchApp.fetch(url, options) Logger.log(response) } When I run this code it retrieves me this info : {"report_run_id":"234313017579333"} But I'm looking for the insights of a campaign and not a report. Has anyone got an idea of why it retrieves me this ? ps: When I run this : https://graph.facebook.com/v4.0/CAMPAIGNID/insights in Facebook's Graph API it gives me the insights of the campaign. So I don't understand with I get another answer when I try to do it from Google Apps Scripts.

Posted on 16 Aug 2022, this text provides information on Facebook Marketing API related to Digital Marketing. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ This sounds like you actually made a POST request, and not a GET - because posting to this edge is supposed to trigger creation of a report in the background, https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group/insights/#Creating: When posting to this edge, an AdReportRun will be created. https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetchurl-params, says in the description of the payload parameter, Certain HTTP methods (for example, GET) do not accept a payload. So because you supplied a payload, that probably makes it use POST, and ignore that you tried to specify 'method' : 'get' Don’t supply a payload, append your access token directly to the URL as a query string parameter instead. var url = "https://graph.facebook.com/v4.0/CAMPAIGNID/insights?access_token=…" (You can probably remove the options object completely then, and call fetch with just the URL as single parameter, because GET is the default anyway.)

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.