How to use openweathermap api key? [closed]

点点圈 提交于 2019-12-06 03:13:23

问题


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


回答1:


How to use API key

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.

<?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.

An example would be

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.

https://chrome.google.com/webstore/search/jsonview?hl=en



来源:https://stackoverflow.com/questions/25575466/how-to-use-openweathermap-api-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!