我正在尝试使用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);
但它正在返回以下错误
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
我已多次验证草稿ID是否正确。
答案 0 :(得分:1)
AFAIK,import { Injectable } from '@angular/core';
import {Http, Response, Request, RequestOptions, RequestOptionsArgs, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
const headers = new Headers({ 'Access-Token': 'My-Access-Token' });
let options = new RequestOptions({ headers: headers });
@Injectable()
export class ServicesService {
private searchUrl: string;
constructor(private _http: Http) { }
searchMusic(str: String, type='artist'){
this.searchUrl = 'https://api.spotify.com/v1/search?query='+str+'&offset=0&limit=20&type='+type+'&market=US'
return this._http.get(this.searchUrl, options)
.map(res=>res.json());
}
}
与draft ID
不同。查看代码,似乎您提供message ID
而不是messageId
。
尝试使用Users.drafts: list
获取不可变草稿ID。这将返回具有以下结构的响应正文
draftId
然后,您可以在使用Users.drafts: update
进行更新时使用"drafts":[
{
"id": draftId,
"message": {
"id": messageId,
"raw": bytes
}
}
]
。
答案 1 :(得分:0)
您需要上传网址。
developers.google.com - Users.drafts:update | Gmail API | Google Developers
https://developers.google.com/gmail/api/v1/reference/users/drafts/update