我试图通过获取记录的Stackdriver API V2为Stackdriver日志。我用UrlFetchApp作出POST请求从谷歌的Apps脚本项目,特别是做到这一点。问题是,它成功运行,但在日志中显示的响应是空的。然而,当我使用apirequest.io,卷曲和谷歌API探险家提出同样的要求,我得到了必要的反应。
我搜索广泛,但无济于事。试图用头,URL,但没有任何实验。
function exportLogs () {
var options = {
"method" : "post",
"headers": {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()},
"resourceNames": [
"projects/MyProject"
],
"pageSize": 1,
}
var response = UrlFetchApp.fetch('https://logging.googleapis.com/v2/entries:list?key=MyApiKey', options)
Logger.log(response)
}
我想是一些日志,但我只得到{}
options
对象使用。payload
为包括请求主体唯一可接受的参数。function exportLogs() {
var options = {
method: "post",
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() }, //Include https://www.googleapis.com/auth/cloud-platform in scopes
payload: JSON.stringify({
resourceNames: ['projects/[PROJECT_ID]'],
pageSize: 1,
}),
};
var response = UrlFetchApp.fetch(
'https://logging.googleapis.com/v2/entries:list?key=MyApiKey',
options
);
Logger.log(response);
}