使用REST API谷歌appscript UrlFetchApp不会允许MongoLab的数据库查

2019-11-03 05:18发布

下面的REST API查询到MongoLab数据库工作正常,在浏览器中:

VAR URL = https://api.mongolab.com/api/1/databases/sis/collections/my-coll?q= {22object%20typ%至22%:22 %%}&apikey 22object 20types%=

然而,当我使用谷歌appscript的UrlFetchApp,如下所示:

VAR oDataObject = JSON.parse(UrlFetchApp.fetch(URL).getContentText());

..then appscript返回以下错误:

参数无效: https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?q=

没有人知道如何解决这个怪癖在谷歌appscript UrlFetchApp?

Answer 1:

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 won't allow MongoLab db queries using REST API