'invalid request' 在 Google Apps 脚本中使用奇妙清单 api 时出错
'invalid request' error while utilizing wunderlist api in Google Apps Script
我正在使用 Google Apps 脚本中的奇妙清单 api 从列表 (https://developer.wunderlist.com/documentation/endpoints/task) 中获取任务。以下代码在函数 getTasks 中执行 UrlFetchApp 的行中给出 'invalid request' 错误。
var accessToken = 'my-access-token';
var clientID = 'my-client-id';
var url = 'https://a.wunderlist.com/api/v1/';
var headers = {
'X-Access-Token': accessToken,
'X-Client-Id': clientID,
'Content-Type': 'application/json'
};
function getTasks(listId){
var payload =
{
"list_id" : listId,
"completed" : true
};
var options =
{
"method" : 'get',
"headers" : headers,
"payload" : JSON.stringify(payload),
};
var response = UrlFetchApp.fetch(url + 'tasks', options);
return response;
}
function main(){
var result = getTasks(my-listid);
}
但是,使用 curl 做同样的事情效果很好;
curl -H "X-Access-Token: my-access-token" -H "X-Client-ID: my-client-id" a.wunderlist.com/api/v1/tasks?list_id=my-list-id
使用另一个 api 使用相同的 header 在 Google Apps 脚本中也能成功;
function getLists() {
var options =
{
"method" : 'GET',
"headers" : headers,
};
var response = UrlFetchApp.fetch(url + 'lists', options);
Logger.log(response);
return response;
}
function main(){
var result = getLists();
}
我想知道第一个代码有什么问题。提前致谢!
这个请求是GET方法。在您的卷曲示例中, list_id=my-list-id
用作查询参数。那么这个修改怎么样呢?
修改后的脚本:
var accessToken = 'my-access-token';
var clientID = 'my-client-id';
var url = 'https://a.wunderlist.com/api/v1/';
var headers = {
'X-Access-Token': accessToken,
'X-Client-Id': clientID,
// 'Content-Type': 'application/json' // This property may not be necessary.
};
function getTasks(listId){
var options =
{
"method" : 'get',
"headers" : headers,
};
var q = "?list_id=" + listId + "&completed=true";
var response = UrlFetchApp.fetch(url + 'tasks' + q, options);
return response;
}
function main(){
var result = getTasks(my-listid);
}
如果这不起作用,我很抱歉。
我正在使用 Google Apps 脚本中的奇妙清单 api 从列表 (https://developer.wunderlist.com/documentation/endpoints/task) 中获取任务。以下代码在函数 getTasks 中执行 UrlFetchApp 的行中给出 'invalid request' 错误。
var accessToken = 'my-access-token';
var clientID = 'my-client-id';
var url = 'https://a.wunderlist.com/api/v1/';
var headers = {
'X-Access-Token': accessToken,
'X-Client-Id': clientID,
'Content-Type': 'application/json'
};
function getTasks(listId){
var payload =
{
"list_id" : listId,
"completed" : true
};
var options =
{
"method" : 'get',
"headers" : headers,
"payload" : JSON.stringify(payload),
};
var response = UrlFetchApp.fetch(url + 'tasks', options);
return response;
}
function main(){
var result = getTasks(my-listid);
}
但是,使用 curl 做同样的事情效果很好;
curl -H "X-Access-Token: my-access-token" -H "X-Client-ID: my-client-id" a.wunderlist.com/api/v1/tasks?list_id=my-list-id
使用另一个 api 使用相同的 header 在 Google Apps 脚本中也能成功;
function getLists() {
var options =
{
"method" : 'GET',
"headers" : headers,
};
var response = UrlFetchApp.fetch(url + 'lists', options);
Logger.log(response);
return response;
}
function main(){
var result = getLists();
}
我想知道第一个代码有什么问题。提前致谢!
这个请求是GET方法。在您的卷曲示例中, list_id=my-list-id
用作查询参数。那么这个修改怎么样呢?
修改后的脚本:
var accessToken = 'my-access-token';
var clientID = 'my-client-id';
var url = 'https://a.wunderlist.com/api/v1/';
var headers = {
'X-Access-Token': accessToken,
'X-Client-Id': clientID,
// 'Content-Type': 'application/json' // This property may not be necessary.
};
function getTasks(listId){
var options =
{
"method" : 'get',
"headers" : headers,
};
var q = "?list_id=" + listId + "&completed=true";
var response = UrlFetchApp.fetch(url + 'tasks' + q, options);
return response;
}
function main(){
var result = getTasks(my-listid);
}
如果这不起作用,我很抱歉。