gpt4 book ai didi

ios - 使用服务帐户访问 IOS 中的 Google 日历

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:10:15 25 4
gpt4 key购买 nike

我需要访问一个非公开的谷歌日历,而不需要用户登录甚至不需要谷歌帐户。

我创建了一个使用服务帐户访问 Google 日历的 Android 应用:

        GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountID)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(licenseFile)
.build();
com.google.api.services.calendar.Calendar.Builder builder = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName(appName);
com.google.api.services.calendar.Calendar client = builder.build();

com.google.api.services.calendar.Calendar.Events.List list = client.events().list(calendarID);
list.setMaxAttendees(maxAttendees);
list.setTimeZone(timeZone);
list.setTimeMin(startTime);
list.setTimeMax(endTime);
list.setOrderBy(orderBy);
list.setShowDeleted(showDeleted);
list.setSingleEvents(true);
Events events = list.execute();

这包括:

  1. 在 Google App 控制台中创建项目
  2. 创建服务帐户
  3. 授予服务帐户访问 Google 日历的权限

效果很好!

我需要在 IOS 中做同样的事情。我已经阅读了我能找到的关于这个主题的所有问题/答案,并找到了非常不同的答案。许多人说谷歌在 IOS SDK 中不允许这样做,因为服务帐户旨在由基于服务器的应用程序使用。我不同意,因为我需要的功能在 Android 中可用。那么,现在呢?

用例是这样的:我的 IOS 应用程序需要访问 Google 日历。如果您不介意使用 OAuth,那部分就不会太难。我对这种方法的问题是:

  • 要求用户拥有 Google 帐户。我的许多用户都是 Apple-Only。我不能要求他们为了使用我的应用而获得 Google 帐户。
  • 我无法公开日历。因此,我需要授予每个新用户访问权限。我想我可以使用基于网络的应用程序来做到这一点,但这并不能解决问题(请参阅之前的问题 - 没有 Google 帐户)。

我确实需要能够在用户不需要 Google 帐户的情况下查询非公开 Google 日历中的事件。解决方案是使用“服务帐户”(我认为)。

我读到一个问题/答案说这是可能的,但解决方案从未发布过。 ( How to list Google Calendar Events without User Authentication )

帮助!!!!

最佳答案

官方文档建议,如果您想处理日历 API(例如),您必须拥有 Google Apps for Work (source)。

If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users.

满足先决条件后,您可以尝试根据您的实现只调用日历 API 的 REST URL(因为文档中似乎没有 iOS 支持或示例)。

关于ios - 使用服务帐户访问 IOS 中的 Google 日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34573041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com