我正在尝试使用Google Appscript调用外部api。但我是 gettting总是错误500。如果有人可以帮助,将不胜感激。
https://demo.overconline.com/api/authenticate的请求失败,返回了代码500。服务器响应被截断:{“ message”:“ error.internalServerError”,“ description”:“内部服务器错误”,“ fieldErrors”:null}(使用MutetHttpExceptions选项检查完整的响应)(第10行,文件“代码”)
function getToken(){
var params ={
"username": "xxxx",
"rememberMe": true,
"password": "xxx",
};
var headers = {'Content-Type':'application/json','method':'post','payload':'params'};
var url = 'https://demo.overconline.com/api/authenticate';
var response = UrlFetchApp.fetch(url,headers);
var result = Utilities.jsonParse(response.getContentText());
var token = result.access_token;
Logger.log(result);
答案 0 :(得分:0)
这是上述代码的正确代码。我通过此代码获得了身份验证令牌。
function getToken(){
var params ={
'username': 'xxxxx',
'rememberMe': true,
'password':'xxxxx'
};
var headers = {'contentType':'application/json','method':'post','payload':JSON.stringify(params)};
var url = 'https://demo.overconline.com/api/authenticate';
var response = UrlFetchApp.fetch(url,headers);
var result = JSON.parse(response.getContentText());
Logger.log(result);
}