我正在尝试向 WB 发出 POST 请求以接收报告。
var options = {
method: 'post',
contentType: 'application/json',
'muteHttpExceptions': true,
headers: {
'Authorization': 'Basic ' + Utilities.base64Encode(apiKey)
},
payload: JSON.stringify({
'period': {
'begin': yesterday+' 00:00:01',
'end':yesterday+' 23:59:59'
},
'page': 1
})
try {
var response = UrlFetchApp.fetch(apiUrl, options);
Logger.log('response: ' + response);
} catch (error) {
Logger.log('Ошибка при выполнении запроса: ' + error);
}
我得到这样的回应:
response: {
"title": "unauthorized",
"detail": "token problem; token is malformed: token contains an invalid number of segments",
"code": "167251cb759b-cc73ad3617b9d5c82732 84bd353bf-75 82f3f335ddde6c815fe840d4ee415696",
"requestId": "82f3f335ddde6c815fe840d4ee415696",
"origin": "s2sauth-ca",
"status": 401,
"statusText": "Unauthorized",
"timestamp": "2024-10-16T15:33:03Z"
}
在具有相同密钥的 python3 上,一切正常,并且我通过 POST 接收数据。我还可以通过 GET 请求接收有关此密钥的报告。
从API描述来看
授权 将令牌添加到授权请求标头
标头参数名称:授权
有人可以告诉我我做错了什么吗?