Skip to content

Instantly share code, notes, and snippets.

@RobSpectre
Created May 22, 2012 16:25
Show Gist options
  • Save RobSpectre/2770084 to your computer and use it in GitHub Desktop.
Save RobSpectre/2770084 to your computer and use it in GitHub Desktop.
Example of a Twilio SMS weather app in PHP
<?php
// Set Weather Underground API key
$WUNDERGROUND_API_KEY = "xxxxxxxxx";
// Include Twilio helper library
require_once('Services/Twilio.php');
// Fetch latest weather for zipcode
$zip = $_REQUEST['FromZip'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.wunderground.com/api/".$WUNDERGROUND_API_KEY."/conditions/q/".$zip.".json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$api_request = curl_exec($ch);
curl_close($ch);
// Decode JSON
$data = json_decode($api_request);
// Create reply
$response = new Services_Twilio_Twiml();
$response->sms("Weather: ".$data->current_observation->weather." Temp: ".$data->current_observation->temperature_string);
print $response;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment