Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 成功使用谷歌搜索api_Python_Google Api_Google Api Python Client - Fatal编程技术网

Python 成功使用谷歌搜索api

Python 成功使用谷歌搜索api,python,google-api,google-api-python-client,Python,Google Api,Google Api Python Client,除了正确的Google公钥之外,我还缺少什么 我收到错误(请参见下面的代码) 在注册以获取 __author__ = '' import pprint from apiclient.discovery import build def main(): ""241d57c296bd9ca73c09a51b422484e879be76cd"" service = build("customsearch", "v1",

除了正确的
Google
公钥之外,我还缺少什么 我收到错误(请参见下面的代码)
在注册以获取

    __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)
错误:

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

看起来您使用了错误的API密钥

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