Facebook Graph API 无法在 UrlFetchApp 上运行
Facebook Graph API not working on UrlFetchApp
我 运行 在 Facebook Graph API Explorer 上查询成功 但是当我 运行 使用 UrlFetchApp 在 Google Apps Script 上进行相同的查询时,我得到一个 Error - Invalid argument.查询是这样的:
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=********
当我 运行 相同的查询 没有 过滤时,它按预期工作!
Json 结果:
编辑:
我尝试 编码 过滤参数,但它引发了一个新错误:
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)
由于错误没有给出任何具体描述,究竟是什么导致了问题?
首先把你的过滤值放到一个数组中:
var fbCallFiltering = [{'field':'campaign.name','operator':'CONTAIN','value':'perf'},{'field':'adset.name','operator':'NOT_CONTAIN','value':'rmk'}];
然后使用JSON.stringify()
var fbCallFilteringString = encodeURIComponent(JSON.stringify(fbCallFiltering));
最后在 &filtering=
之后使用 URL 中的 fbCallFilteringString
变量来调用 UrlFetchApp。
这应该有效。
我 运行 在 Facebook Graph API Explorer 上查询成功 但是当我 运行 使用 UrlFetchApp 在 Google Apps Script 上进行相同的查询时,我得到一个 Error - Invalid argument.查询是这样的:
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=********
当我 运行 相同的查询 没有 过滤时,它按预期工作!
Json 结果:
编辑: 我尝试 编码 过滤参数,但它引发了一个新错误:
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)
由于错误没有给出任何具体描述,究竟是什么导致了问题?
首先把你的过滤值放到一个数组中:
var fbCallFiltering = [{'field':'campaign.name','operator':'CONTAIN','value':'perf'},{'field':'adset.name','operator':'NOT_CONTAIN','value':'rmk'}];
然后使用JSON.stringify()
var fbCallFilteringString = encodeURIComponent(JSON.stringify(fbCallFiltering));
最后在 &filtering=
之后使用 URL 中的 fbCallFilteringString
变量来调用 UrlFetchApp。
这应该有效。