Jquery Google安全浏览API 403错误:请求缺少有效的API密钥

Jquery Google安全浏览API 403错误:请求缺少有效的API密钥,jquery,ajax,google-cloud-platform,safe-browsing,safe-browsing-api,Jquery,Ajax,Google Cloud Platform,Safe Browsing,Safe Browsing Api,我的ajax代码如下所示: $("#my_form").submit(function(event){ event.preventDefault(); //prevent default action var api_url = "https://safebrowsing.googleapis.com/v4/threatMatches:find?" var key = 'A..............................s' api_url

我的ajax代码如下所示:

    $("#my_form").submit(function(event){
    event.preventDefault(); //prevent default action 

    var api_url = "https://safebrowsing.googleapis.com/v4/threatMatches:find?"
    var key = 'A..............................s'
    api_url += key

    console.log(api_url);

    var payload = 
    {
        "client":{
            "clientId": "2815.........................apps.googleusercontent.com",
            "clientVersion": "1.0.0",
        },
        "threatInfo": {
            "threatTypes":      ["MALWARE", "SOCIAL_ENGINEERING"],
            "platformTypes":    ["WINDOWS"],
            "threatEntryTypes": ["URL"],
            "threatEntries": [
              {"url": "http://www.pitt.edu/"},
              {"url": "http://www.exchange.pitt.edu/"}
            ]
          }
    };

    $.ajax({
        type: "POST",
        url: api_url,
        contentType: "applicaiton/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify(payload),
    success:function (data) {
        console.log("ok");
         console.log(data);
    },
    error:function(status){
        console.log("fail");
        console.log(status);
    }
    });
我已经为我的项目启用了API

我为api密钥创建了凭据。我已尝试启用誓言2.0凭据以获取我的客户端id


您的问题是将API密钥添加为未命名参数

更改此行:

api_url += key
致:


实际上,您没有在此处传递所需的查询字符串参数
key
。您可以像这样添加它:

api_url += `key=${key}`;
api_url += `key=${key}`;