我尝试只从Outbox收到邮件:
String user = "me";
ListMessagesResponse response = mService.users().messages().list(user).execute();
//set selected labels
//[CATEGORY_PERSONAL, CATEGORY_SOCIAL, Регистрации, CATEGORY_FORUMS, IMPORTANT, CATEGORY_UPDATES, CHAT, SENT, INBOX, TRASH, CATEGORY_PROMOTIONS, DRAFT, SPAM, STARRED, UNREAD]
List<String> labelIds = new ArrayList<>();
labelIds.add("SENT");
List<Message> messages = new ArrayList<Message>();
while (response.getMessages() != null) {
messages.addAll(response.getMessages());
if (response.getNextPageToken() != null) {
String pageToken = response.getNextPageToken();
response = mService.users().messages().list(user).setLabelIds(labelIds).setPageToken(pageToken).execute();
} else {
break;
}
}
但我也收到了Inbox消息
答案 0 :(得分:0)
我需要在第一个响应行上设置过滤器。 这段代码工作:
String user = "me";
//set selected labels
//[CATEGORY_PERSONAL, CATEGORY_SOCIAL, Регистрации, CATEGORY_FORUMS, IMPORTANT, CATEGORY_UPDATES, CHAT, SENT, INBOX, TRASH, CATEGORY_PROMOTIONS, DRAFT, SPAM, STARRED, UNREAD]
List<String> labelIds = new ArrayList<>();
labelIds.add("SENT");
ListMessagesResponse response = mService.users().messages().list(user).setLabelIds(labelIds).execute();
List<Message> messages = new ArrayList<Message>();
while (response.getMessages() != null) {
messages.addAll(response.getMessages());
if (response.getNextPageToken() != null) {
String pageToken = response.getNextPageToken();
response = mService.users().messages().list(user).setPageToken(pageToken).execute();
} else {
break;
}
}