在Google Apps脚本中,我通过HTTPS请求调用我的Cloud函数,然后调用API,并转发回响应。我这样做是因为API需要静态IP地址。从外部API返回到Cloud Functions时,我收到一条成功的状态:200消息。然后,我尝试将响应转发回GAS,并获得状态:502 in GAS。
我认为状态:502是内存错误吗?此函数适用于较小的响应。
我的Google Apps脚本函数:
function gas_function(){
var token = ScriptApp.getIdentityToken();
var params = {muteHttpExceptions: true, headers: { Authorization: 'Bearer ' + token } };
var url = 'https://'+REGION+'-'+PROJECT_ID+'.cloudfunctions.net/'+RECEIVING_FUNCTION;
var response = UrlFetchApp.fetch(url,params);
// I should be getting my 'Status:200' response from the Cloud Function with my data
// This works with small datasets, but with a large dataset I get
// Response Code = 502 Error: could not handle the request
return response;
}
我的Google Cloud Function:
exports.cloud_function = functions.https.onRequest(async (request, response) => {
var url = 'https://externalapi.com/info/';
var api_response = await axios.get(url);
console.log(api_response.data); // this works! I have a response with ~12000 data records
// Now I just need to send it back to Google Apps Script
response.status(200).send(api_response.data);
});
发布于 2021-02-05 05:05:20
如果UrlFetchApp.fetch()
收到的响应大于气体限制(50MB),您将得到一个状态:502响应。
API端的解决方案:
执行GAS操作
有关配额和限制的链接,请参阅评论-谢谢
https://stackoverflow.com/questions/66052445
复制相似问题