NodeMCU 上的 Google Maps Geolocation API 的 HTTP POST 请求失败

我正在使用 Wemos D1 Mini 开发板,尝试使用周围的 AP 和 Google Maps Geolocation API 获取板子的位置。该板运行 NodeMCU 并使用 Lua 编程。

目前我的代码如下:

function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel)
    body = {}
    body["wifiAccessPoints"] = {}
    for bssid,v in pairs(t) do
        this_m = {}
        this_m.macAddress = bssid
        table.insert(body.wifiAccessPoints, this_m)
    end

    ok, json = pcall(sjson.encode, body)
    if ok then
      http.post('https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyC4IZU8CEB0jvSblOHqYm********', 'Content-Type: application/json\r\n', json,
      function(code, data)
        if (code < 0) then
          print("HTTP 请求失败")
        else
          print(code, data)
        end
      end)
    else
      print("编码失败!")
    end

end
wifi.sta.getap(1, listap)

它创建的 JSON 看起来不错,我可以使用 Postman 等工具进行请求,但每次运行脚本时,请求都会失败。有什么想法吗?

点赞