Gmail草稿API返回404错误 [英] Gmail Draft API returning 404 error
问题描述
我正在尝试使用Google Apps脚本更新草稿邮件。这里是代码。
var forScope = GmailApp.getInboxUnreadCount();
var params = {method:put,
contentType:application / json,
headers:{Authorization:Bearer+ ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
message:{
id:draftId,
raw:draftBody
}
})
};
var resp = UrlFetchApp.fetch(https://www.googleapis.com/gmail/v1/users/me/drafts/+ draftId,params);
但它返回以下错误
<$ p
error:{
errors:[
{
domain:global,
原因:notFound,
message:Not Found
}
],
code:404,
message:Not找到
}
我已多次验证草稿ID是正确的。
AFAIK, draft ID
code>消息ID 。看看你的代码,好像你正在提供 messageId
而不是 draftId
。
尝试使用获取不可变更的草稿ID Users.drafts:list
。这将返回具有以下结构的响应主体:
草稿:[
{
id :draftId,
message:{
id:messageId,
raw:bytes
}
}
]
然后,您可以使用 draftId
a href =https://developers.google.com/gmail/api/v1/reference/users/drafts/update =nofollow noreferrer> Users.drafts:update
。
I am trying to update a draft message with Google Apps Script. Here is the code.
var forScope = GmailApp.getInboxUnreadCount();
var params = {method:"put",
contentType: "application/json",
headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
muteHttpExceptions:true,
payload:JSON.stringify({
"message": {
"id": draftId,
"raw": draftBody
}
})
};
var resp = UrlFetchApp.fetch("https://www.googleapis.com/gmail/v1/users/me/drafts/"+draftId, params);
But it is returning following error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
I have verified multiple times that the draft id is correct.
AFAIK, draft ID
is different from the message ID
. Looking at your code, seems like you're supplying messageId
instead of draftId
.
Try obtaining the immutable draft ID using Users.drafts: list
. This will return a response body with the following structure
"drafts":[
{
"id": draftId,
"message": {
"id": messageId,
"raw": bytes
}
}
]
Then, you can use draftId
when you update using Users.drafts: update
.
这篇关于Gmail草稿API返回404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!