ios - 访问未配置 : Google URL Shorten API on iOS Simulator

标签 ios objective-c ios8 google-api google-url-shortener

我已将 Google URL-Shorten API 集成到我的 iOS 应用程序中,仅用于测试目的。 我的应用程序的 Bundle ID 由我添加到 Authorized iOS Applications 列表中以发送请求。

但每当我使用 NSURLRequest 发送一个 HTTP POST 请求时,我在响应 JSON 中收到以下错误:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
    "extendedHelp": "https://console.developers.google.com"
   }
  ],
  "code": 403,
  "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
 }
}

我不知道如何解决这个问题。我做出的一种猜测是“可能我必须在在线应用程序上使用 API”

支持我猜测的引用来自 API 文档

If your application accesses APIs directly from iOS, you will need the application's Bundle ID and (optionally) its Apple App Store ID:

The application's Bundle ID is the bundle identifier as listed in the app's .plist file. For example: com.example.myapp.
The application's App Store ID is in the app's iTunes URL so long as the app was published in the Apple iTunes App Store. For example, in the app URL http://itunes.apple.com/us/app/google+/id447119634, the App Store ID is 447119634.

最佳答案

当您设置 API key 时,请勿提供可选的 iOS 包 ID,除非您使用的是 OAuth 2.0。 Google API Keys for iOS Usage

我遇到了同样的错误,删除了 bundle id 并清除了 403,同时仍然在带有 NSURLSession 的 HTTP post 请求上使用 API key 。

您可以通过访问 Google 开发人员控制台,单击 API 和授权下的“凭据”,然后单击 API key 名称来消除错误。然后您将看到一个屏幕,您可以在其中删除与 API key 关联的 iOS 包 ID。然后点击保存按钮,重新测试。

关于ios - 访问未配置 : Google URL Shorten API on iOS Simulator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27562500/

相关文章:

ios - UIButton 上的 UILongPressGestureRecognizer 不起作用

objective-c - 在 Objective-C 中比较两次的最好/最简单的方法是什么?

ios - 分配 : *** error for object: Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug in Magical record IOS

Swift 从 WebView 调用电话

objective-c - 网络扩展 - NEVPNManager

ios - AVAudioSession 重新激活问题

ios - Xcode 12 beta 6 中缺少 availableRawPhotoPixelFormatTypes

ios - 如何从通用链接获取 url?

objective-c - iPhone 6 Plus 在横向模式下自动隐藏状态栏?

ios - 为什么具有单个 Cocoapod 依赖项的样板 Cocoa Touch Framework 项目中的样板单元测试甚至没有运行就失败了?