首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >请求缺少一个有效的API键Google搜索API python。

请求缺少一个有效的API键Google搜索API python。
EN

Stack Overflow用户
提问于 2022-04-26 11:16:54
回答 1查看 472关注 0票数 0

为了使用Google,我遵循了相同的这里步骤,但我得到了以下错误:

代码语言:javascript
运行
复制
"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.">" 

我想我在谷歌云项目中有一些事情要做,但我不知道,

代码(Python):

代码语言:javascript
运行
复制
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')
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-26 11:56:34

您的没有实际为开发人员和项目键设置环境变量,也就是说,在执行key = os.environ.get()之前,应该在终端窗口中完成export GCS_DEVELOPER_KEY=__your_dev_api_key__

请参阅文档

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72012976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档