【发布时间】:2021-11-25 14:55:56
【问题描述】:
我正在尝试使用open weather API,我刚刚创建了一个帐户并获得了我的 API 密钥,之后我写了 https://api.openweathermap.org/data/2.5/weather?q=London&appid=
在 zsh 中,它返回:
[1] 12567 zsh:未找到匹配项: https://api.openweathermap.org/data/2.5/weather?q=London jack@jackengtwistios-Mac-mini node-andrew % [1] + exit 1 curl https://api.openweathermap.org/data/2.5/weather?q=London
在 bash 中:
[1] 12715 jackengtwistios-Mac-mini:node-andrew jack$ {"cod":401, "message": "API 密钥无效。请参阅 http://openweathermap.org/faq#error401 了解更多信息。"}
但在 chrome 浏览器中它只返回预期的结果:
{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":800,"main":"Clear","description":"clear 天空","icon":"01d"}],"base":"stations","main":{"temp":279.99,"feels_like":279.99,"temp_min":278.87,"temp_max":280.86, “压力”:1017,“湿度”:72},“能见度”:10000,“风”:{“速度”:0.45,“度”:331,“阵风”:2.24},“云”:{“所有":7},"dt":1637851503,"sys":{"type":2,"id":2019646,"country":"GB","sunrise":1637825718,"sunset":1637856008}," timezone":0,"id":2643743,"name":"London","cod":200}
【问题讨论】:
-
“无效的 API 密钥” - 您在 CURL 的哪个位置传递 api 密钥?