我设法通过 Postman 执行 API POST 请求,但一旦针对 Google App Script 进行修改,它就不起作用了。我认为这可能与格式有关body,我无法复制new URLSearchParams()GAS 中的对象(我相信我正在发送 JSON)。
谢谢。
邮递员(工作)-JavaScript 获取
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("client_id", "XXXX");
urlencoded.append("client_secret", "XXXX");
urlencoded.append("grant_type", "client_credentials");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
fetch("https://apigateway.criteo.com/oauth2/token", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Run Code Online (Sandbox Code Playgroud)
卷曲
curl --location --request POST 'https://apigateway.criteo.com/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=XXXX' \
--data-urlencode 'client_secret=XXXX' \ …Run Code Online (Sandbox Code Playgroud)