accessNotConfigured : Google URL Shorten API on iOS Simulator

1.3k views Asked by At

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

There are 3 answers

0
Linda Lawton - DaImTo On

As the error states you have not properly configured access to the API or you are not authenticating the app.

Authorizing requests and identifying your application

Every request your application sends to the Google URL Shortener API needs to identify your application to Google. There are two ways to identify your application: using an OAuth 2.0 token (which also authorizes the request) and/or using the application's API key. Here's how to determine which of those options to use:

You need to set up the project in the Google Developer console enable the URL Shorter API, and use either the API key to access it or Oauth2.

0
thomasdao On

You might have missed passing the API keys. You could see how to pass the key here.

0
drshock On

When you setup your API key, do NOT provide an optional iOS bundle id unless you are using OAuth 2.0. Google API Keys for iOS Usage

I ran into this same mistake, removed the bundle id and cleared the 403 while still using an API key on an HTTP post request with NSURLSession.

You can remove the mistake by accessing the Google developers console, clicking "Credentials" under APIs & auth, and then clicking on API key name. You will then get a screen where you can delete the iOS bundle ID you associated with the API key. Then click the save button, and retest.