带 iOS 的 Gmail API - 接收电子邮件 [英] Gmail API with iOS - getting emails

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

问题描述

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

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.

目前的工作流程如下:

  1. 使用框架框架 由 Google 提供.我已完成此步骤,我的应用可以成功授权 Gmail 帐户.

  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.

下载电子邮件:

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

From the documentation, it seems that this is the API call to show a list of messages:

GET https://www.googleapis.com/gmail/v1/用户/用户 ID/消息

我的问题:

我是否需要编写自己的 Objective-C 包装器来调用这个 API 来下载消息,或者像 MailCore 让我更轻松地做到这一点?据我了解,这个 API 代替了 IMAP,这是 MailCore 实现的内容.

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.

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

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. Gmail API,它是一种 RESTful API,可用于访问 Gmail 邮箱和发送邮件.该 API 支持 Gmail 用户界面提供的许多基本操作,例如阅读、撰写和发送邮件.它还允许您管理话题和消息上的标签以及查询特定消息和话题.

  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.

  • 您可以围绕 API 编写自己的 Objective-C 包装器,以向 API 参考 但工作量很大,你必须编写你需要的一切,错误管理,验证等......

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

您可以使用 Google API 客户端库用于 Objective-C 推荐用于访问 iOS 和 Mac OS X 应用程序的基于 JSON 的 Google API.此 API 支持包括 Gmail 在内的许多 Google 产品.

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 和 SMTP 协议受 Gmail 支持并包括 OAuth 2.0 授权.

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

  • 您可以使用任何现有的 IMAP 和 SMTP 库,这些库支持您想要的 SASL,并且应该与 Gmail 支持的 SASL XOAUTH2 机制兼容.例如,您可以按照您的建议使用 MailCore.

<小时>

在我看来,您正在寻找与 Gmail 邮箱交互的最简单方式,因此 Gmail API 是授权访问用户 Gmail 数据的最佳选择.


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.

我会选择 Objective-C 的 Google API 客户端库 这样您就不必围绕 API 编写自己的包装器,并且可以开箱即用地使用它.

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.

您看到了检索线程页面的 Python 示例代码:

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

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

Objective-C 的 Google API 客户端库您可以使用多种选项来做同样的事情,例如可能包含垃圾邮件和结果中的垃圾文件夹、最大结果数、搜索匹配特定查询的线程等.

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;

Google API 客户端库支持 API 参考中描述的所有操作对于 Objective-C.

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

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

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