【问题标题】:Enabling server side offline access to Google API from iOS app从 iOS 应用启用服务器端对 Google API 的离线访问
【发布时间】:2017-03-03 21:10:44
【问题描述】:

我正在尝试启用服务器端对 Google API 的离线访问,用户从 iOS 应用程序进行身份验证。这是为了让服务器能够持续访问 iOS 应用之外的 Google API。

Google 记录了以下方法: https://developers.google.com/identity/sign-in/ios/offline-access

我已经完全按照他们的文档进行了准系统项目。但是,每当我尝试用一​​次性授权代码交换访问和刷新令牌时,我都会在交换过程中收到 'redirect_uri_mismatch' 错误。

我搜索了论坛,并且许多人建议配置没有重定向 URI 的 Google API 项目 OAuth 2.0 客户端 ID(来自 Google 开发者控制台)。然而,这会导致错误'Missing property "redirect_uris" in a client type of "web"'

我也尝试过其他 OAuth 2.0 客户端 ID 类型(例如,其他),但没有成功。

有没有人能够让这个流程工作?任何帮助将不胜感激!

【问题讨论】:

    标签: python google-api google-api-python-client oauth2client


    【解决方案1】:

    我也碰到过这个。谷歌的例子是错误的,或者至少是不完整的。您必须在开发者控制台上设置一个重定向 uri 并将其传递给 oauth 客户端,如下所示:

    credentials = client.credentials_from_clientsecrets_and_code(
    CLIENT_SECRET_FILE,
    ['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
    auth_code, None, "your redirect uri")
    

    这里有完整的文档http://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html

    【讨论】:

    • 已经 3 年了,但仍然:“你的重定向 uri”实际上应该是什么?假设它在服务器端(无头)运行,没有浏览器,用户已经同意(这就是我们首先获得服务器身份验证代码的方式),我不想要重定向 URI - 我只想要一个有效且授权的 Python 客户端接口继续发出命令..
    【解决方案2】:

    在您的代码中将redirect_uri 设置为urn:ietf:wg:oauth:2.0:oob,它用于安装的应用程序。正如@oravecz 超过here 所提到的。这对我有用。

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 2016-10-13
      • 2018-03-15
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2019-12-28
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多