Facebook API Marketing with UrlFetchApp

Digital Marketing Facebook Marketing API 3 years ago

8.63K 1 0 0 0

_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.

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 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.)
0 views
0 shares

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.

Similar Forum


Q

What are the best SEO tools for a personal website? What website or tools should I use to build and...

What are the best SEO tools for a personal website? What website or tools should I use to build and...
Q

Why is keyword research important?

Why is keyword research important?
Q

What is SEO ?

What is SEO ?