使用 axios 访问谷歌图片搜索 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"
    }
}

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...