使用axios访问google图像搜索API时请求错误



我想在谷歌上搜索三张图片显示在我的网站上。

我认为这是api获取信息所需的最小信息,但也许我错过了一些东西。在这个问题上,Google可没帮上什么忙。

const GOOGLE_API_URL = 'https://www.googleapis.com/customsearch/v1';
async function google_image_search(searchTerm){
const response = await axios({
method:'GET',
url:GOOGLE_API_URL,
params:{
q:searchTerm,
num:3,
searchType:'image',
key:API_KEY,
}
});
return response;
}
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}

我明白了。我必须在谷歌开发者设置的自定义搜索引擎的控制面板中将其设置为图像。

最新更新