我正在尝试使用我的谷歌日历并将每一天作为文档发布到通过谷歌脚本进行的沃森发现。我的代码看起来像这样。
var headers={
"User-Agent": "CreateCalendarListJson",
"Authorization": "Basic " + Utilities.base64Encode( authdata.username+":"+authdata.password)
};
//headers.contentType="application/json";
var parms={"headers":headers};
url=newurl+"/v1/environments/"+discoveryData.environmentID+
"/collections/"+discoveryData.collection_ID+"/documents/?version=2017-09-01";
parms.method="POST";
parms.file={
'value':JSON.stringify(jsonEvent),
'options':{
'filename':jsonEvent.filename,
'contentType':"application/json"
}
}
console.info('discovery add document %s',JSON.stringify(parms));
response=UrlFetchApp.fetch(url,parms);
但是,这会收到错误 415 不支持的媒体类型。虽然 application/json 是受支持的类型,但我已经相应地设置了 contentType。有什么建议么?
当 UrlFetchApp.Fetch 运行时,parms 变量如下所示:
{"headers":
{"User-Agent":"CreateCalendarListJson",
"Authorization":"Basic ZTIyNTEwM............................tHcg=="},
"method":"POST",
"file":{"value":"{\"title\":\"Events 10/13/2017\",\"filename\":\"Events_10_13_2017\",\"text\":[{\"date\":\"10/13/2017\",\"summary\":\"assignment 1\"}]}",
"options":{"filename":"Events_10_13_2017",
"contentType":"application/json"}}}"