6
votes

Google Custom Search is returning this 403 error from my iPhone 7.1 app. This is the response when run in the simulator:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
   }
  ],
  "code": 403,
  "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
 }
}

Is there a flaw in the steps below? Iā€™d like to establish a working CSE setup process specific to iOS apps. The screenshots at each step will hopefully help and not confuse!

  1. Create a Custom Search Engine (CSE) at https://www.google.com/cse/

  2. From Setup -> Basics, get the Search engine ID. CSE search engine ID

  3. Test the CSE at https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list

    • Set "q" to any test query terms ("foo bar") and "cx" to the Search engine ID in step 2.
    • Press "Execute" and receive your search results. They work. Google also provides this URL which we'll re-use in Xcode in step 8. Google API Explorer test results
  4. To get ourselves a key for ID and billing purposes, create a new project at https://console.developers.google.com/

  5. Under APIs & auth -> APIs -> Enable "Custom Search API." No other APIs are enabled. Developer Console APIs

  6. Under APIs & auth -> Credentials -> Create a new iOS key. Developer Console Credentials Note: I also tried a browser key and the search result returned "Error 400: Invalid Value." I returned to the iOS key since I'm on iOS and the error seemed less severe.

  7. Add to this key your bundle identifier from Xcode. Xcode bundle identifier

  8. In Xcode make your GET request to the URL in step 3. Replace {YOUR_API_KEY} with the key from your credentials in steps 6-7.

GET request in Xcode

NSData *response contains the error 403 shown above. Thanks for any thoughts on what's wrong!

1
I am facing the same error, did you get any solution for this? ā€“ Suhit Patil
thanks for the reminder! I answered with what worked for me. ā€“ Orbusii
This question did help me to figure out the complete process here is all what you ned to know to get it to work: stackoverflow.com/a/27039037/656600 ā€“ rptwsthi

1 Answers

6
votes

It was missing the header field X-Ios-Bundle-Identifier.

NSString *bundleID = @"com.yourCompany.yourApp";
//...define request as above
[request setHTTPMethod:@"GET"];
[request setValue:bundleID forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];