Gmail-API Threads.list未在响应中返回邮件 修改后的脚本:注意:参考文献:

问题描述

我正在尝试使用Gmail-API从用户那里获取所有线程,并通过使用threads.list在该线程中拥有所有消息。在gmail文档中,它指出以下是命中此端点的响应:

{
 "threads": [
   users.threads Resource
 ],"nextPageToken": string,"resultSizeEstimate": unsigned integer
}

我有一个简单的功能可以实现这个目标

const {google} = require('googleapis');

/**
 * Lists the threads in the user's account.
 *
 * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
 */

export function listThreads(auth,fn) {
    const gmail =  google.gmail({version: 'v1',auth});

    gmail.users.threads.list({
      userId: 'me',q: 'to:[email protected] '
    },(err,res) => {
      if (err) throw 'The API returned an error: ' + err;
      
      // fn is a callback used to return data to the handler since
      // the res object is in the callback of thread.list
      fn(res)
    });

  }

以下是我得到的答复(我将实际电子邮件替换为abc并替换了我的令牌以保护隐私):

{
    "gmail": {
        "config": {
            "url": "https://www.googleapis.com/gmail/v1/users/me/threads?q=to%3Aabc%40abc.com","method": "GET","headers": {
                "Accept-Encoding": "gzip","User-Agent": "google-api-nodejs-client/0.7.2 (gzip)","Authorization": "Bearer 123456","Accept": "application/json"
            },"params": {
                "q": "to:[email protected]"
            },"responseType": "json"
        },"data": {
            "threads": [
                {
                    "id": "173bf0efdd1f1dc4","snippet": "Hello abc,Attached are the screenshots of my website for the requirements. Please send me an email with all of the information I'm asking for in the forms. For the colors,here is the site to","historyId": "4759550"
                }
            ],"resultSizeEstimate": 1
        },"headers": {
            "alt-svc": "h3-29=\":443\"; ma=2592000,h3-27=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","cache-control": "private","connection": "close","content-encoding": "gzip","content-type": "application/json; charset=UTF-8","date": "Thu,20 Aug 2020 01:13:07 GMT","server": "ESF","transfer-encoding": "chunked","vary": "Origin,X-Origin,Referer","x-content-type-options": "nosniff","x-frame-options": "SAMEORIGIN","x-xss-protection": "0"
        },"status": 200,"statusText": "OK"
    }
}

如您所见,res.data.threads的messages属性完全丢失。我将不胜感激。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)