Gmail API中是否可以在邮件列表方法中包含其他字段(例如,主题,正文)? [英] Is there a way in Gmail API to include extra fields (e.g. subject, body) in the message list method?

查看:55
本文介绍了Gmail API中是否可以在邮件列表方法中包含其他字段(例如,主题,正文)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试"部分文档允许我播放API,而字段选择器则允许我选择很多字段,例如标头,原始等.但是尝试使用API​​时,它们实际上都没有出现.我唯一看到的还是消息ID和线程ID.

The "Try it" part documentation allows me to play the API, and the field selector allow me to select a lot of fields, e.g. header, raw, etc. But none of them actually showed up when tried the API. The only thing I saw were still just the message ID and the thread ID.

https://developers.google.com/gmail/api/v1/reference /users/messages/list

例如以下:

GET https://www.googleapis.com/gmail/v1/users/{user_id}/messages?**fields=messages(historyId%2Cid%2Cpayload%2Craw%2CsizeEstimate%2Csnippet%2CthreadId)**&key={YOUR_API_KEY}

返回:

{
 "messages": [
  {
   "id": "146da54fe3dc089e",
   "threadId": "146da54fe3dc089e"
  },
  {
   "id": "146da41d9486982f",
   "threadId": "146da41d9486982f"
  },
  ...
}

但是我希望所请求的额外字段也会返回.

But I would expect the extra fields requested are returned too.

是否有办法使它正常工作? 我知道有一种单独的方法来获取单个消息,但如果可能的话,希望将其批量处理.

Is there a way to get this working? I know there is a separate method to get an individual message but like to get them batch if possible.

推荐答案

messages.list返回的不仅仅是标识符.不知道字段选择器是什么,但我不相信它被使用.

messages.list does not return much more than just the identifiers. not sure what the field selector is but i don't believe it's used.

不过,您可以使用批处理的message.get,然后在第二个呼叫中一次检索很多消息:

however you can use a batched message.get to then retrieve many messages at once in a second call:

批处理请求包含多个API调用,这些调用组合到一个HTTP请求中.本节详细描述批处理语法.稍后,有一个示例.

A batch request consists of multiple API calls combined into one HTTP request. This section describes the batch syntax in detail; later, there's an example.

注意:一组一起批处理的n个请求计为n个请求,而不是一个请求计入使用限制.批处理请求在处理之前被分解为一组请求.

Note: A set of n requests batched together counts toward your usage limit as n requests, not as one request. The batch request is taken apart into a set of requests before processing.

发件人: https://developers.google.com/storage/docs/json_api /v1/how-tos/batch

使用Gmail API和批处理,下面是一些示例代码:

With the Gmail API and batch here're some sample code:

GTLBatchQuery *batchQuery = [GTLBatchQuery batchQuery];

[gmailMessageIds enumerateObjectsUsingBlock:^(NSNumber *messageId, NSUInteger idx, BOOL *stop) {
    GTLQueryGmail *query = [GTLQueryGmail queryForUsersMessagesGet];
    query.userId = self.account.email;
    query.identifier = [NSString stringWithFormat:@"%llx", [messageId unsignedLongLongValue]];
    query.format = kGTLGmailFormatRaw;

    [batchQuery addQuery:query];
}];


[self.gmailService executeQuery:batchQuery completionHandler:^(GTLServiceTicket *ticket, GTLBatchResult *result, NSError *error) {
    NSArray *gmailMessages = result.successes.allValues; // This is an array of GTLGmailMessage objects
    ... 
}];

这篇关于Gmail API中是否可以在邮件列表方法中包含其他字段(例如,主题,正文)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆