在尝试使用UrlFetchApp通过Auth进行GET请求时,我遇到了以下问题。
这就是我所拥有的:
function getAllProducts() {
const key = "MY KEY";
const secret = "MY SECRET";
const options = {
"headers": {
"Authorization": "Basic " + Utilities.base64Encode(key + ":" + secret),
"Cache-Control": "no-cache", // This didn't seem to matter
"Pragma": "no-cache" // This didn't seem to matter either
}
};
const url = 'https://www.my-domain/wp-json/wc/v3/products?per_page=1&page=1'; // Seems to just be ignoring these?!?!?!?
Logger.log(url); // This logs the correct url with params
return callAPI(url, options);
}
function callAPI(url, options) {
const response = UrlFetchApp.fetch(url, options); // After first call I can just remove options and it'll work without Auth?!?!?
const jsonResponse = response.getContentText();
const data = JSON.parse(jsonResponse);
return data;
}
总结:
options
中删除.fetch(url, options)
,并且仍然给出相同的响应。因此,显然是在缓存某些内容-但这并不能解释它忽略了查询参数。这是裁判的弯腰:
curl https://www.my-domain.co.za/wp-json/wc/v3/products?per_page=1 -u <KEY>:<SECRET>
我希望在这里有所帮助-真的可以把我的头发拔出来!