简体   繁体   English

无法使用JavaScript GMAIL API创建草稿

[英]Unable to create Draft using JavaScript GMAIL API

This question has been asked a few times but none of the answers has solved my problem. 这个问题已被问过几次,但没有一个答案解决了我的问题。

I am trying to save a draft using Gmail API in JavaScript. 我正在尝试使用JavaScript中的Gmail API保存草稿。 But I get the following error. 但是我收到以下错误。

 "message": "Missing draft message"

I know the reason is that I am unable to encode my arguments properly in RCF 2822 format although I have taken all the necessary measures. 我知道原因是我无法以RCF 2822格式正确编码我的参数,尽管我采取了所有必要的措施。 Following is my code: 以下是我的代码:

        gapi.client.load('gmail', 'v1', function() {
          var request = gapi.client.gmail.users.drafts.create({
            'userId': "me",
            'draft': {
              'message': {
                'raw': btoa("From: me\r\nTo:" + "hello@person.com" + "\r\nSubject:"+ "subject" + "\r\n\r\n" + "message")
              }
            }
          });
          request.execute(function(data){
            console.log(data)
          });
        });

I have properly converted the draft email using btoa Can't see what I am missing. 我已经使用btoa正确转换了草稿电子邮件无法看到我缺少的内容。

Some of the answers on SC are related to Ruby. SC上的一些答案与Ruby有关。 Almost none of the solutions work in my scenario. 几乎所有解决方案都不适用于我的场景。 I have tried passing simple string as draft message still get the same issue. 我尝试传递简单的字符串作为草稿消息仍然得到相同的问题。

Please guide me where I am wrong. 请指导我错在哪里。

PS I am successfully able to send email via Gmail API using almost the same code and encoding. PS我使用几乎相同的代码和编码成功地通过Gmail API发送电子邮件。 But I can't save messages as drafts. 但我无法将信息保存为草稿。

I just encountered this issue, it looks like the API client changed the way it expects the payload. 我刚刚遇到这个问题,看起来API客户端改变了它对预期有效负载的方式。 I had to remove the draft attribute to fix this : 我不得不删除draft属性来解决这个问题:

      var request = gapi.client.gmail.users.drafts.create({
        userId: "me",
        message: {
            raw: ...)
          }
      }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM