Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Custom Search: 403 error in iOS

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!

like image 597
Orbusii Avatar asked Jun 13 '14 19:06

Orbusii


People also ask

How do I fix Google authorization error 403?

"code": 403, "message": "The user does not have sufficient permissions for file {fileId}." To fix this error, instruct the user to contact the file's owner and request edit access. You can also check user access levels in the metadata retrieved by files.

What is http error 403 in Google Drive?

This error is usually labeled as the http error 403. There may be several reasons why you are seeing this error message. It may be related to expired or cached browser cookies, a corrupted Google Drive download, and more.


1 Answers

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"];
like image 198
Orbusii Avatar answered Oct 02 '22 19:10

Orbusii