问题描述
我有openweathermap api密钥,但是如何在PHP中使用它呢?并且天气报告应该使用城市名称而不是位置天气ID
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
推荐答案
如何使用API密钥
How to use API key
将以下参数添加到GET请求中:APPID = APIKEY示例:api.openweathermap.org/data/2.5/forecast/city?APPID = YOURAPIKEY &您想要什么.
Add the following parameter to the GET request: APPID=APIKEYExample: api.openweathermap.org/data/2.5/forecast/city?APPID=YOURAPIKEY & what ever you want to request.
<?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);
?>
要请求特定信息,只需查看API接受的键并附加&到网址KEY = VAL的末尾.
To request specific information just look at the keys that the API accepts and append & to the end of the url KEY=VAL.
一个例子是
http://api.openweathermap.org/data/2.5/weather?APPID = YourAPIKey& q =伦敦
在使用API时,我还想添加一些东西,建议安装JSON查看器插件.我将JSONView安装为Google chrome扩展程序,非常适合查看json.
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.
https://chrome.google.com/webstore/search/jsonview?hl=zh-CN
这篇关于如何使用openweathermap API密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!