Skip to content

Instantly share code, notes, and snippets.

@maccath
Created August 25, 2012 22:16
Show Gist options
  • Save maccath/3471494 to your computer and use it in GitHub Desktop.
Save maccath/3471494 to your computer and use it in GitHub Desktop.
Get a user's latest tweet with cURL; no API key needed
<?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
}
@artoon1
Copy link

artoon1 commented Jul 29, 2014

Not working yet due to twitter api changed. can you update that.

@mkasapoglu
Copy link

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