Facebook Graph API not working on UrlFetchApp

不想你离开。 提交于 2021-02-18 19:00:53

问题


I run a query on Facebook Graph API Explorer successfully but when I run the same query on Google Apps Script with UrlFetchApp I get an Error - Invalid argument. The query is this:

https: //graph.facebook.com/v4.0/act_1015703131******/insights?fields=spend&level=account&date_preset=yesterday&filtering=[{field:campaign.name,operator:CONTAIN,value:perf},{field:adset.name,operator:NOT_CONTAIN,value:rmk}]&access_token=********

When I run the same query without filtering it works as expected!

Json Result:

EDIT: I tried to encode the filtering parameters and it throws a new error:

Request failed for https://graph.facebook.com returned code 400. Truncated server response: {"error":{"message":"(#100) param filtering must be an array.","type":"OAuthException","code":100,"fbtrace_id":"AMw2vkaHXbuiVSQuSNg28yZ"}} (use muteHttpExceptions option to examine full response)

What is causing the problem exactly since the error doesn't give any specific description?


回答1:


First put your filtering value into an array:

var fbCallFiltering = [{'field':'campaign.name','operator':'CONTAIN','value':'perf'},{'field':'adset.name','operator':'NOT_CONTAIN','value':'rmk'}];

Then use JSON.stringify()

var fbCallFilteringString = encodeURIComponent(JSON.stringify(fbCallFiltering));

Finally use the fbCallFilteringString variable in the URL you use to make the UrlFetchApp call after the &filtering=.

This should work.



来源:https://stackoverflow.com/questions/58658777/facebook-graph-api-not-working-on-urlfetchapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!