Yahoo weather YQL API without authentication

weather

Sometime you may need to show weather status on your own/client’s website. There are lots of web-services that do that for you but most of them are paid services. After frantic search I found Yahoo weather YQL API that uses YQL (Yahoo Query Language) this API doesn’t require any authentication for weather report (No OAuth required).

Yahoo weather YQL API PHP Script

To create your own Yahoo weather API you need to Get your API Keys first.

In above Yahoo example it’ll show weather report of “chicago, il“.


For for clarity or flexibility I have added above function in PHP Class:

By default Yahoo weather API sends temperature in fahrenheit. If you want to show temperature in celsius then you need to change temperature from fahrenheit to celsius.

Changes temperature from fahrenheit to celsius

Yahoo Weather API Codes

Now you need to map the yahoo weather codes & images respectively. Here is the link for Yahoo weather codes

https://developer.yahoo.com/weather/documentation.html#codes

This is the sample images mapped with yahoo weather codes:

yahoo weather codes

We can save these images having their weather code in the name. Use that images to show weather status with icon for more clarity.

Weather icons SVG (vector)

If you want to use SVG (vector) images for more clarity you may download SVG weather icons. I am assuming you have downloaded these SVG weather icons now you need to add these stylesheet code in you style.css file.

Now combine all the functions together in one class that will show weather icon.

If you do not want to use SVG icons then you need to comment following div from above code snippet:

And, un-comment the following code from above snippet:

Weather-Sample

Here is the full PHP snippet to show Yahoo Weather without any authentication:

Source: My GitHub Account

Leave a Reply