简体   繁体   English

缺少草稿邮件-JavaScript Gmail API-如何构建请求正文?

[英]Missing draft message - javascript Gmail API - how to structure body of the request?

At the recent Google IO conference new Gmail APIs were announced. 在最近的Google IO会议上,宣布了新的Gmail API。 Client libraries are missing examples and documentation which is understandable given the short time that has gone by. 客户端库缺少示例和文档,考虑到时间太短,这是可以理解的。

UPDATE: It wasn't clear in the original question - I've already tried encoding the whole message as Base64 string. 更新:原始问题尚不清楚-我已经尝试将整个消息编码为Base64字符串。

I'm trying to create a new draft message: 我正在尝试创建新的消息草稿:

var request = gapi.client.gmail.users.drafts.create({
    'message' : {
      'raw' :  Base64.encode("To: someguy@example.com\r\nFrom: myself@example.com\r\nSubject: my subject\r\n\r\nBody goes here")
      // 'raw' : "VG86IHNvbWVndXlAZXhhbXBsZS5jb20KRnJvbTogbXlzZWxmQGV4YW1wbGUuY29tClN1YmplY3Q6IG15IHN1YmplY3QKCkJvZHkgZ29lcyBoZXJl"
      // 'raw' : "From: me@example.com\nTo:you@example.com\nSubject:Ignore\n\nTest message\n"

    }
});

request.execute(function(response) {

});

Can you please provide me with the correct syntax to do that? 您能为我提供正确的语法吗?

(Base64.encode is coming from http://www.webtoolkit.info/javascript-base64.html - tried using plain text, encoded version on the fly and hardcoded values from other question) (Base64.encode来自http://www.webtoolkit.info/javascript-base64.html-尝试使用纯文本,即时编码版本和其他问题的硬编码值)


Related questions: 相关问题:

Handy links just for reference: 方便的链接仅供参考:


So I'm trying to find a solution in related questions addressing Ruby and C# by recreating JSON structure but I've reached the point that I need a Rubber Duck or Stack Overflow. 因此,我正在尝试通过重新创建JSON结构来解决有关Ruby和C#的相关问题的解决方案,但我已经达到需要橡皮鸭或堆栈溢出的地步。

Thank you in advance for providing a hint on how to structure the object passed to the API method. 预先感谢您提供有关如何构造传递给API方法的对象的提示。

Since the question is the same, the answer will be identical: 由于问题是相同的, 答案将是相同的:

'raw' should contain the entire (RFC822) email, complete with body and headers. “原始”应包含整个(RFC822)电子邮件,并带有正文和标头。

While @rds answer is technically correct: "base64 encode complete message", the fully working answer is as follows... The correct structure of the request: 虽然@rds答案在技术上是正确的:“ base64编码完整消息”,但完全有效的答案如下...请求的正确结构:

'draft': {
  'message': {
    'raw': base64EncodedEmail
  }
}

Source: https://developers.google.com/gmail/api/v1/reference/users/drafts/create (scroll down and then choose JavaScript from dropdown menu) 来源: https : //developers.google.com/gmail/api/v1/reference/users/drafts/create (向下滚动,然后从下拉菜单中选择JavaScript)

I was missing the essential draft property. 我没有基本的财产草案

The trick is it's not just normal base64 encoding it's WEB SAFE (aka URL SAFE) base64 encoding. 诀窍是,它不仅是普通的base64编码,而且是WEB SAFE (又名URL SAFE)base64编码。 It's similar except two characters in the alphabet are different to make sure the entire blob works well in URLs and javascript/json. 相似之处在于字母中的两个字符不同,以确保整个Blob在URL和javascript / json中都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript 中的“缺少草稿消息” - 'Missing draft message' in Javascript 无法使用JavaScript GMAIL API创建草稿 - Unable to create Draft using JavaScript GMAIL API 如何在 Node.JS 中使用 gmail API 创建带有附件的草稿邮件? - How to create draft message with attachment using gmail API in Node.JS? 如何使用gmail api javascript获取读取和未读消息列表 - how to get read and unread message list using gmail api javascript Gmail API:无法请求未读邮件 - Gmail API : unable to request unread message 在 javascript 中获取 Gmail 邮件正文时删除 html 格式 - Remove html formatting when getting Body of a gmail message in javascript 将Google API与Jav​​aScript结合使用-如何包括请求正文 - Using google API with javascript - how to include request body 在javascript中发布请求以json主体来休息api - post request to rest api with json body in javascript 如何在 api 使用 Z686155AF75A60A0F6E9D80C1FZEDD 发布请求后 Laravel 中的 flash 消息? - How to flash message in Laravel after api post request with JavaScript? Javascript和回调和deferred。 如何在google gmail API请求完成后运行某个功能? - Javascript and callbacks and defered. How can I run a function after a google gmail API request completes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM