2016-11-27 62 views
1

我嘗試從發件箱中只得到郵件:Android版Gmail API獲取發件箱中的郵件

  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; 
      } 
     } 

,但我得到的消息收件箱中也

+0

爲什麼你不'第一'ListMessagesResponse' setLabelIds'呢? – Tholle

+1

謝謝@Tholle,這是正確的答案。 –

回答

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; 
      } 
     } 
相關問題