【问题标题】:Gmail Rest API json to send messageGmail Rest API json 发送消息
【发布时间】:2022-01-30 03:47:45
【问题描述】:

我在向 gmail api 发送 json 请求时遇到问题。 我可以访问独家新闻https://www.googleapis.com/auth/gmail.send,它允许我访问发送方法。

在谷歌文档中,他们声明其余部分需要在下面提供此数据。 https://developers.google.com/gmail/api/reference/rest/v1/users.messages

但我不会填满它们,在它们里面放什么? 有没有人通过仅发送 json 的方式使用 api?

我在堆栈上进行了研究,但没有找到有这种困难的人。并且在 google 文档中没有示例。

{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": string,
  "internalDate": string,
  "payload": {
    object (MessagePart)
  },
  "sizeEstimate": integer,
  "raw": string
}

【问题讨论】:

    标签: json api rest gmail


    【解决方案1】:

    消息应编码为 base64。您可以通过将此代码粘贴到节点 REPL 或像这样的在线节点编译器中来生成一个 https://replit.com/languages/nodejs

    function createMessageJson(){
        const messages = [
            'From: NAME <foo@email.com>',
            'To: Name <foobar@email.com>',
            'Content-Type: text/html; charset=utf-8',
            'MIME-Version: 1.0',
            'Subject: Re: SUBJECT',
            '',
            'BODY_TEXT',
            '',
        ];
    
    
        function encodedMessage (){
            return Buffer.from(messages.join('\n'))
                .toString('base64')
                .replace(/\+/g, '-')
                .replace(/\//g, '_')
                .replace(/=+$/, '');
        }
    
    
      return JSON.stringify({
                raw: encodedMessage()
        });
    }
    
    console.log(createMessageJson())
    

    【讨论】:

      猜你喜欢
      • 2017-03-03
      • 2014-08-19
      • 2020-07-12
      • 1970-01-01
      • 2018-02-17
      • 2018-07-14
      • 2016-05-29
      • 2016-12-31
      • 2016-11-29
      相关资源
      最近更新 更多