Gmail API with iOS - getting emails

后端 未结 1 1519
时光说笑
时光说笑 2021-02-06 14:41

I\'m trying to understand how the Gmail API works. My goal is to retrieve a list of all of a user\'s emails in their inbox, downloaded to an NSArray.

Current

相关标签:
1条回答
  • 2021-02-06 15:14

    The basic workflow is correct and you have multiple ways to achieve what you want:

    1. The Gmail API which is a RESTful API that can be used to access Gmail mailboxes and send mail. The API supports many of the basic operations available through the Gmail user interface like reading, composing, and sending mail. It also lets you manage labels on threads and messages and query for specific messages and threads.

      • You can write your own Objective-C wrapper around the API to make the correct HTTP request to the differents endpoints described in the API reference but it's a lot of work, you have to write everything you need, error management, validation, etc...

      • You can use the Google APIs Client Library for Objective-C recommended for accessing JSON-based Google APIs for iOS and Mac OS X applications. This API include support for many Google products including Gmail.

    2. IMAP and SMTP protocols are supported by Gmail and include OAuth 2.0 authorization.

      • You can use any existing IMAP and SMTP libraries which supports SASL you want and should be compatible with the SASL XOAUTH2 mechanism supported by Gmail. You can use MailCore for example like you suggested.

    It seems to me you're looking for the easiest way to interact with Gmail mailboxes so the Gmail API is the best choice for authorized access to a user's Gmail data.

    I would go for the Google APIs Client Library for Objective-C so you won't have to write your own wrapper around the API and can use it out of the box.

    You saw the python example code to retrieve a page of threads:

    threads = gmail_service.users().threads().list(userId='me').execute()
    

    The Google APIs Client Library for Objective-C will give you methods to do the same thing with multiple options like possibility to include the spam & trash folder in results, maximum number of results, search for a thread matching a specific query, etc.

    + (id)queryForUsersThreadsList;
    

    All actions described in the API reference are supported by Google APIs Client Library for Objective-C.

    0 讨论(0)
提交回复
热议问题