简体   繁体   English

该请求缺少有效的 API 密钥 Google 搜索 API python

[英]The request is missing a valid API key Google search API python

I followed the same steps here exactly to use the Google search API but I got the following error:我完全按照此处的相同步骤使用 Google 搜索 API,但出现以下错误:

"googleapiclient.errors.HttpError: <HttpError 403 when requesting 
https://customsearch.googleapis.com/customsearch/v1?q=Persian+Cat&searchType=image&num=10&start=1&imgType=photo&fileType=jpg%7Cpng&safe=high&alt=json 
returned "The request is missing a valid API key.". Details: "The request is missing a valid API key.">" 

I think there is something that I have to do in google cloud project but I can't know,我认为我必须在谷歌云项目中做一些事情,但我不知道,

Code (Python):代码(蟒蛇):

from google_images_search import GoogleImagesSearch
import os

key = os.environ.get('XXX') 
cx  = os.environ.get('XXX')
gis = GoogleImagesSearch(key, cx)
_search_params = {
    'q'       : 'Persian Cat',
    'num'     : 10,
    'safe'    : 'high',
    'fileType': 'jpg|png',
    'imgType' : 'photo',
}

gis.search(search_params=_search_params,custom_image_name='persian')
for image in gis.results():
    print('i got here')
    image.download('/images/persian') # download location
    image.resize(500, 500)            # resize the image

os.listdir('/images/persian')

You haven't actually set the environment variable for the Developer and project keys ie before you can do key = os.environ.get() , you should have done export GCS_DEVELOPER_KEY=__your_dev_api_key__ in a terminal window您实际上还没有为 Developer 和项目密钥设置环境变量,即在您可以执行key = os.environ.get()之前,您应该在终端 window 中完成export GCS_DEVELOPER_KEY=__your_dev_api_key__ your_dev_api_key__

Refer to the documentation参考文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当向 Vision API 产品搜索发出请求时,出现错误“消息”:“请求缺少有效的 API 密钥。” - When making a request to the Vision API Product Search an error occurs "message": "The request is missing a valid API key." 具有域范围委托的 Google 日历 API:events.watch 方法失败并显示“请求缺少有效的 API 密钥” - Google Calendar API with domain wide delegation: events.watch method fails with "The request is missing a valid API key" com.google.firebase.FirebaseException:发生内部错误。 [ API 密钥无效。 请传递有效的 API 密钥。 ] - com.google.firebase.FirebaseException: An internal error has occurred. [ API key not valid. Please pass a valid API key. ] POST 到 api 网关时无法解析“授权标头中的无效键 = 值对(缺少等号)” - Unable to resolve " not a valid key=value pair (missing equal-sign) in Authorization header" when POSTing to api gateway 使用 Python 中的访问密钥验证 Google 表格 API - Authenticate Google Sheets API Using Access Key in Python Firebase:错误(auth/api-key-not-valid.-please-pass-a-valid-api-key.) - Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.) 谷歌开发者控制台 API 密钥 - Google developer console API Key 未捕获(承诺)FirebaseError:Firebase:错误(auth/api-key-not-valid.-please-pass-a-valid-api-key.)(Netlify) - Uncaught (in promise) FirebaseError: Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.) (Netlify) 用于本地测试的 Google API 密钥 - Google API Key for Local Testing 谷歌语音 API Python 无响应 - Google Speech API Python not responding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM