Facebook Graph API在UrlFetchApp上不起作用 [英] Facebook Graph API not working on UrlFetchApp

查看:84
本文介绍了Facebook Graph API在UrlFetchApp上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Facebook Graph API Explorer 成功 上运行查询,但是当我使用UrlFetchApp在Google Apps脚本上运行相同的查询时,错误-无效的参数.查询是这样的:

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=昨天& filtering = [{field:campaign.name,operator:CONTAIN,value:perf},{field:adset.name,operator:NOT_CONTAIN,value:rmk}]& access_token = ********

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结果:

我试图编码过滤参数,并引发了新错误:

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?

推荐答案

首先将您的过滤值放入数组中:

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'}];

然后使用JSON.stringify()

Then use JSON.stringify()

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

最后在& filtering = 之后用于进行UrlFetchApp调用的URL中使用 fbCallFilteringString 变量.

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

这应该有效.

这篇关于Facebook Graph API在UrlFetchApp上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆