Gmail API与iOS - 获取电子邮件 [英] Gmail API with iOS - getting emails

查看:136
本文介绍了Gmail API与iOS - 获取电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解 Gmail API 的工作原理。我的目标是在收件箱中检索用户的所有电子邮件列表,并将其下载到 NSArray



目前的工作流似乎如下:


  1. 使用框架由Google提供。我已经完成 这个步骤,我的应用程序可以成功授权一个Gmail帐户。


  2. 下载电子邮件:



    文档 ,似乎这是API调用来显示消息列表:



    GET https://www.googleapis.com/gmail/v1/users/userId/messages



  3. 我的问题



    <使这个API调用来下载消息,或者像 MailCore 这样可以让我更容易地做到这一点?据了解,这个API代替了IMAP,这是 MailCore 实现的。



    我知道如何在Python中执行此操作,例如 https://developers.google.com/gmail/api/quickstart/quickstart-python ,但我看不到如何将此代码移植到Objective-C。

    解决方案

    基本的工作流程是正确的,你有多种方法可以实现你想要的:


    1. Gmail API ,它是可用于访问Gmail邮箱和发送邮件的RESTful API。该API支持通过Gmail用户界面提供的许多基本操作,如阅读,撰写和发送邮件。它还允许您管理线程和消息上的标签,并查询特定的消息和线程。




      • 您可以编写自己的Objective- C包装API,以便对 API参考但这是很多工作,你必须编写你需要的所有东西,错误管理,验证等...


      • 你可以使用<推荐用于访问基于JSON的Google的href =https://code.google.com/p/google-api-objectivec-client/ =noreferrer> Google API客户端库Objective-C适用于iOS和Mac OS X应用程序的API。此API包括对许多Google产品(包括Gmail)的支持。



    2. IMAP和SMTP 协议由Gmail支持,并包括OAuth 2.0授权。




      • 您可以使用任何现有的IMAP和SMTP库,支持您所需要的SASL兼容Gmail支持的SASL XOAUTH2机制。您可以像您建议的那样使用 MailCore







    在我看来,您正在寻找与Gmail邮箱进行互动的最简单方法,以便Gmail API是授权访问用户Gmail数据的最佳选择。



    我会去 Objective-C的Google API客户端库,因此您不必在API周围编写自己的包装器,并可以开箱即用。



    你看到python示例代码来检索一段线程:

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

    Objective-C的Google API客户端库将给你方法做同样的事情与多个选项,如可能性包括垃圾邮件&垃圾文件夹在结果中,最大数量的结果,搜索匹配特定查询的线程等。

      +(id)queryForUsersThreadsList ; 

    API参考由Google API客户端库for Objective-C支持。


    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:

    1. 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.

    2. 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:

    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.

    这篇关于Gmail API与iOS - 获取电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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