php 如何使用 openweathermap api 密钥?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25575466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use openweathermap api key?
提问by Nayanendu Mondal
I have openweathermap api key , but how can I use it in PHP ? and the weather report should be report from a city name, not from the location weather ID
我有 openweathermap api 密钥,但如何在 PHP 中使用它?并且天气报告应该从城市名称报告,而不是从位置天气 ID 报告
回答by Mark
How to use API key
如何使用 API 密钥
Add the following parameter to the GET request: APPID=APIKEY Example: api.openweathermap.org/data/2.5/forecast/city?APPID=YOURAPIKEY& what ever you want to request.
将以下参数添加到 GET 请求:APPID=APIKEY 示例:api.openweathermap.org/data/2.5/forecast/city ?APPID= YOURAPIKEY以及您想要请求的内容。
<?php
$request = 'http://api.openweathermap.org/data/2.5/forecast/city?APPID=***YOURAPIKEY***';
$response = file_get_contents($request);
$jsonobj = json_decode($response);
print_r($jsonobj);
?>
To request specific information just look at the keys that the API accepts and append & to the end of the url KEY=VAL.
要请求特定信息,只需查看 API 接受的键并将 & 附加到 url KEY=VAL 的末尾。
An example would be
一个例子是
http://api.openweathermap.org/data/2.5/weather?APPID=YourAPIKey&q=London
http://api.openweathermap.org/data/2.5/weather?APPID=YourAPIKey&q=London
I would also like to add when working with API's I recommend installing a JSON viewer plugin. I got the JSONView installed as a Google chrome extension which is brilliant for viewing json.
我还想在使用 API 时添加我建议安装 JSON 查看器插件。我将 JSONView 安装为 Google chrome 扩展程序,这对于查看 json 非常有用。