Want to implement our weather API but not sure how to get started? Here's a quick guide to using World Weather Online's APIs with PHP. Read more here: Want to implement our weather API but not sure how to get started? Here's a quick guide to using World Weather Online's APIs with PHP.
2. www.worldweatheronline.com
This is a quick starter guide to get up and running using our
weather API’s with PHP. Have no fear, no previous PHP
knowledge is required to get started!
We will cover the basic concepts of storing your credentials
in local variables, and making a CURL request to the World
Weather Online API service to get a 5 day weather forecast
for New York city (maximum 5 days forecast for free
accounts on the local weather API).
What’s this about?
3. www.worldweatheronline.com
Getting your API Key
Your API key is a unique randomly generated key which
identifies you or your applications account. You can get your
own API key by simply registering. Your API key will look
something like this:
a7e124b57d3e3d3671960ddcbe467
(note: This is not an actual key)
4. www.worldweatheronline.com
Getting started
Firstly let’s setup some variables that we will use later by
opening up a new PHP file – I’ve called this one index.php.
<?php
// index.php file
// We'll store our API key and the free, non HTTPS URL for the API
$apiKey = ‘a7e124b57d3e3d3671960ddcbe467′;
$freeHttpsUrl = ‘https://api.worldweatheronline.com/free/v2/weather.ashx';
Now we need to start looking at how the API actually works.
5. www.worldweatheronline.com
Required API Request Parameters
The API accepts a number of parameters so that we can specify exactly
what we need. Below I have listed the parameters that are required
for each request and a small explanation of each.
Parameter Description Required Values
q Location Required See note below
num_of_days
Number of days of
forecast
Required, except for
monthly average
Integer. Example:
num_of_days=2
key The API key Required
Provided when
registering your
application
For a full list of the parameters visit this section of the API Documentation.
6. www.worldweatheronline.com
For the rest of the API with PHP user guide,
including how to make the request with PHP
Curl, click the link:
Getting started with World Weather Online
API with PHP