成功使用Google搜索API



除了正确的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">

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

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

相关内容

  • 没有找到相关文章