Google appscript UrlFetchApp 不允许使用 REST API 的 MongoLab db 查询 [英] Google appscript UrlFetchApp won't allow MongoLab db queries using REST API
问题描述
以下对 MongoLab 数据库的 REST API 查询在浏览器中运行良好:
The following REST API query to the MongoLab database works fine in a browser:
var url = https://api.mongolab.com/api/1/databases/sis/collections/my-coll?q={%22Object%20Type%22:%22Object%20Types%22}&apiKey=
var url = https://api.mongolab.com/api/1/databases/sis/collections/my-coll?q={%22Object%20Type%22:%22Object%20Types%22}&apiKey=
但是,当我使用 Google appscript 的 UrlFetchApp 时,如下:
However, when I use Google appscript's UrlFetchApp, as follows:
var oDataObject = JSON.parse(UrlFetchApp.fetch(url).getContentText());
var oDataObject = JSON.parse(UrlFetchApp.fetch(url).getContentText());
..then appscript 返回以下错误:
..then appscript returns the following error:
无效参数:https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?q=
有谁知道如何解决 Google appscript UrlFetchApp 中的这个怪癖?
Does anyone know how to work around this quirk in Google appscript UrlFetchApp?
推荐答案
var sQuery = encodeURIComponent(JSON.stringify(oQuery));
var sUrl = 'https://api.mongolab.com/api/1/databases/'
+ MWO_GetDbName() +'/collections/my- coll?'
+ 'q=' + sQuery + '&apiKey=' + MWO_GetDbKey();
var oDataObject = JSON.parse(UrlFetchApp.fetch(sUrl).getContentText());
return oDataObject;
这篇关于Google appscript UrlFetchApp 不允许使用 REST API 的 MongoLab db 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!