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
.
Currently the workflow seems to be as follows:
Authorize my iOS app with OAuth 2.0 using the frameworks provided by Google. I have completed this step and my app can successfully authorize a gmail account.
Download emails:
From the documentation, it seems that this is the API call to show a list of messages:
GET https://www.googleapis.com/gmail/v1/users/userId/messages
My Question:
Would I need to write my own Objective-C wrapper to make this API call to download the messages, or would something like MailCore allow me to do this more easily? As I understand it, this API is in replace of IMAP, which is what MailCore implements.
I understand how to do this in Python, as per the example https://developers.google.com/gmail/api/quickstart/quickstart-python but I don't see how I'd port this code to Objective-C.
The basic workflow is correct and you have multiple ways to achieve what you want:
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.
IMAP and SMTP protocols are supported by Gmail and include OAuth 2.0 authorization.
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.