如何通过 Android 中的联系人(电子邮件 ID)获取最少 API 调用次数的 Gmail 消息数?

How to get number of gmail messages by contact (email id) in Android with minimum number of API calls?

通过 contact/emailId 在 android 中使用最少 API 调用次数获取消息的最佳方法是什么?

您可以 list messages 发送 to/from 特定电子邮件地址:

请求

q = to:example@gmail.com OR from:example@gmail.com

GET https://www.googleapis.com/gmail/v1/users/me/messages?q=To%3Aexample%40gmail.com+OR+from%3Aexample%40gmail.com&access_token={YOUR_API_KEY}

回应

{
 "messages": [
  {
   "id": "1516c4a48a1d6ec9",
   "threadId": "1516c3bc5769405d"
  },
  {
   "id": "1516c46d828b2470",
   "threadId": "1516c3bc5769405d"
  }, ...
 ],
 "resultSizeEstimate": 6
}

那么您将不得不 get these messages individually, just asking for the timestamp if that is all you need (this can be done as a single http-request with a batch-请求,但仍会从您的 API 配额中抽取同样多的积分)

请求

fields = internalDate

GET https://www.googleapis.com/gmail/v1/users/me/messages/1516c4a48a1d6ec9?fields=internalDate&access_token={YOUR_API_KEY}

回应

{
 "internalDate": "1449220786000"
}

internalDate 表示消息存储在 Google 的时间,自纪元以来以毫秒为单位。