[英]Google Apps Script get response from external API
I'm using a google apps script to get data from an external API. 我正在使用谷歌应用程序脚本从外部API获取数据。
This is the code I'm using: 这是我正在使用的代码:
function cenas(){
var url='https://app.ecwid.com/api/v1/XXX/orders';
var response = UrlFetchApp.fetch(url);
Logger.log(response);
}
I get the following error: 我收到以下错误:
Access token or API key not found in request parameters
I know I must provide the secret authentification key. 我知道我必须提供秘密认证密钥。 But how do I include that in the function?
但是我如何在函数中包含它?
You can pass a second parameter to UrlFetchApp.fetch() for params. 您可以将第二个参数传递给UrlFetchApp.fetch()以获取参数。 Inside those params you can pass things such as your method and headers - which is where you would pass your Authorization header.
在这些参数中,您可以传递诸如方法和标题之类的内容 - 这是您传递Authorization标头的位置。
Depending on your params, your code would probably look something like: 根据你的参数,你的代码可能看起来像:
var headers = {
Authorization: 'Bearer ' + accessToken
};
var params = {
'method': 'GET',
'headers': headers,
'contentType': 'application/json'
}
var response = UrlFetchApp.fetch(url, params);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.