Implementing Google custom search API in iOS

Do you wanna implement google custom search API, in an application (ios/android)? Alright! Here, this link will solve everything for you.

Go check that!

Checked? ‘And’ back! That means you are one of my kind, unlike the geniuses who understand the encrypted documentation of these tech giants.

It took me 6-7 hours and tens of url keys (support URL and forum links) to decrypt the documentation they provided. I wanna save that time for you folk. Here is step by step process to for implementing google search api.

Initial X step will be common for all, and last few steps are dedicated for the application developers. In this document you’ll learn:

  • Steps to implement the search API
  • Pictorial detail of steps
  • Make a final run of your application

Brief Step of the process:

  1. Create a Google account (ignore if you have one)
  2. You may found some piece of information related to pricing at the bottom of this page helpful(you can ignore this too)
  3. Create a project and generate an API key
  4. Go to google console and create a project
    1. After the project created, click on it to go to its detail.
    2. On the left bar under Auth&API, segment, click on APIs.
    3. Now you’ll find CustomSearchAPI link in Browse APIs section (as it is not activated by default), turn it on by clicking on the button at right.
    4. Now click on Credentials, just below APIs option
    5. On this page under “Public API Access” click on Create New Key Button, for now, choose browser key(as at first we wanna test it on a browser), create it and leave it, as it is for now.
  5. Create a Custom Search Engine
    1. Now on the new tab, open the Custom Search Engine page. On this page click on Create a custom search engine, button
    2. That will lead you to create a new search engine page, here give your domain name in “Sites to search” field. (If you don’t have one no worries, give anything, that has www. in the start and .com in the end)
    3. Fill name, if it hasn’t pick one already, then click on create.
    4. So you got a jumping robot to congratulate you? 😉 Yeah, that’s it. In this page step up to “Modify your search engine”, by clicking on, “Control Panel” button
    5. There you are, now turn on the Image Search, (if you want to)
    6. Also in “Sites to search” section, select, “Search the entire web but emphasize on the included item”, instead of, the default one, which is “Search only included site”
    7. That is it, at the bottom of this page click on update. And then come back to the middle of the page and under the “Detail” title, click on Search engine ID, copy the Id, paste it somewhere.
  6. Make a search, using get request:
    1. To make a get request use this request URL
    2. In it replace, {API_KEY} which you have created under “Create a project and generate API key” section
    3. And replace {SEARCH_ENGINE_KEY} with the Search engine Id you just copy pasted Call it with some different value, at query string, then ‘a’, https://www.googleapis.com/customsearch/v1?q=a&key={API_KEY}&cx={SEARCH_ENGINE_KEY} change a with anything you wanna search you must have got the beautiful JSON of search result
  7. Other Stuff
    1. If you wanna see the request status, go back to your project page, that how may request placed, how many of those failed, etc. Click on the overview and you will get the graph for that, love you google
    2. If you have trouble with JSON, here are some links at your service,
      1. What is JSON 12?
      2. Use JSON in ios.
      3. Use JSON in android.

Thanks, you can always comment if you have any query.