Created
August 25, 2012 22:16
-
-
Save maccath/3471494 to your computer and use it in GitHub Desktop.
Get a user's latest tweet with cURL; no API key needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return a user's latest tweet using cURL | |
* | |
* @param string $username The username for whom you wish to fetch a tweet | |
* @return mixed The tweet if it exists, NULL otherwise | |
*/ | |
function latest_tweet($username) { | |
$url = 'http://search.twitter.com/search.json?from='.$username; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
$data = json_decode($data); | |
return $data->results[0]; // The latest tweet | |
} |
Not working due to Twitter REST API v1 is no longer active.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working yet due to twitter api changed. can you update that.