Book Image

Twilio Cookbook: Second Edition

By : Roger Stringer
Book Image

Twilio Cookbook: Second Edition

By: Roger Stringer

Overview of this book

Table of Contents (20 chapters)
Twilio Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the local weather forecast


The weather lookup portion of this app will work in a similar way to the find portion. When we send a text saying "weather", it returns today's and tomorrow's forecast. We're going to use Yahoo's own weather lookup API for this is already built into Yahoo's YQL system.

We're also going to make use of Yahoo's geo places system that will take our phone number's registered location and return a unique ID that the weather service will use to perform the lookup.

Our query will actually return two messages. The first message is the current forecast; the second message is the forecast for tomorrow.

Getting ready

The complete source code for this recipe can be found in the Chapter5/ folder.

How to do it...

Now, this recipe will extend our search system to include a local weather lookup. Create a file called weather.php in the pages folder and add the following code to it:

<?php
$location = whereami( $from );
$results = weather( $location->woeid );
$forecast = $results...