Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Created December 28, 2010 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismytton/757700 to your computer and use it in GitHub Desktop.
Save chrismytton/757700 to your computer and use it in GitHub Desktop.
<?php
/**
* Simple twitter stream function
*
* Usage: $tweets = userTimeline("hecticjeff");
*/
function userTimeline($screenName)
{
// Create a remote connection
$twitter = curl_init("http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$screenName}");
// Tell curl to return the body of the response
curl_setopt($twitter, CURLOPT_RETURNTRANSFER, true);
// Execute the request
$response = curl_exec($twitter);
// Decode the results
return json_decode($response);
}
<?php
// Loop over tweets
foreach (userTimeline("hecticjeff") as $tweet) {
echo $tweet->text . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment