如何使用 openweathermap api 密钥? [英] How to use openweathermap api key?

查看:340
本文介绍了如何使用 openweathermap api 密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 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 key的使用方法

在GET请求中添加如下参数:APPID=APIKEY示例:api.openweathermap.org/data/2.5/forecast/city?APPID=YOURAPIKEY &你想要什么.

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);
?>

要请求特定信息,只需查看 API 接受的密钥并附加 &到 url 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=en

这篇关于如何使用 openweathermap api 密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆