5

I have integrated the Google URL-Shorten API in my iOS App just for testing purpose. The Bundle ID of my app is added by me in the list of Authorized iOS Applications to send the request.

But whenever I send an HTTP POST request using NSURLRequest, I get the following error in response 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."
 }
}

I cannot figure out how to solve this. One guess I made is "may be I have to use the API on an Online App"

Supporting reference to my guess is from API Documentation

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

3 回答 3

3

设置 API 密钥时,请勿提供可选的 iOS 捆绑包 ID,除非您使用的是 OAuth 2.0。 适用于 iOS 的 Google API 密钥

我遇到了同样的错误,删除了 bundle id 并清除了 403,同时仍在使用 NSURLSession 的 HTTP 发布请求上使用 API 密钥。

您可以通过访问 Google 开发者控制台,单击 APIs & auth 下的“凭据”,然后单击 API 密钥名称来消除错误。然后,您将看到一个屏幕,您可以在其中删除与 API 密钥关联的 iOS 捆绑 ID。然后点击保存按钮,重新测试。

于 2015-11-02T15:34:53.053 回答
1

由于错误表明您没有正确配置对 API 的访问权限,或者您没有对应用程序进行身份验证。

授权请求并识别您的应用程序

您的应用程序向 Google URL Shortener API 发送的每个请求都需要向 Google 识别您的应用程序。有两种方法可以识别您的应用程序:使用 OAuth 2.0 令牌(也授权请求)和/或使用应用程序的 API 密钥。以下是如何确定要使用哪些选项:

您需要在Google Developer 控制台中设置项目,启用URL Shorter API,并使用 API 密钥或 Oauth2 访问它。

于 2014-12-19T09:46:47.073 回答
0

您可能错过了传递 API 密钥。您可以在此处查看如何传递密钥。

于 2015-05-22T05:05:43.223 回答