Search code examples
pythongoogle-apigoogle-api-python-client

using google search api successfully


What am I missing here except proper Google public key?
I am getting the error (see below code)
while registering to get

    __author__ = ''

    import pprint

    from apiclient.discovery import build

    def main():
        ""241d57c296bd9ca73c09a51b422484e879be76cd""
        service = build("customsearch", "v1",
                        developerKey=google_api_public_key)

        res = service.cse().list(
            q='lectures').execute()
        pprint.pprint(res)

if __name__ == '__main__':
    main()

   service = build("customsearch", "v1",
                    developerKey="public_key")  
    res = service.cse().list(
        q='lectures').execute()  
        #, cx='017576662512468239146:omuauf_lfve').execute()  
    pprint.pprint(res)

Error:

apiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/customsearch/v1?q=lectures&alt=json&key=241d57c296bd9ca73c09a51b422484e879be76cd returned "Bad Request">

Solution

  • It looks like you are using the wrong API key.

    {
     "error": {
      "errors": [
       {
        "domain": "usageLimits",
        "reason": "keyInvalid",
        "message": "Bad Request"
       }
      ],
      "code": 400,
      "message": "Bad Request"
     }
    }