Skip to content

Instantly share code, notes, and snippets.

@arush
Created August 13, 2011 03:57
Show Gist options
  • Save arush/1143464 to your computer and use it in GitHub Desktop.
Save arush/1143464 to your computer and use it in GitHub Desktop.
twitter curl
<?php
/**
* fly2mars-media
* http://www.fly2mars-media.de
* http://www.fly2mars-media.de/seoblog
*/
/*
* Twitter connector class
*/
class twitterConnect
{
// http://www.webmasterpro.de/coding/article/php-twitter-in-eine-webseite-einbinden.html
protected $twitter = null;
public function __construct($userName = '', $pw = '')
{
$this->twitter = curl_init();
curl_setopt($this->twitter, CURLOPT_USERPWD, $userName . ':' . $pw);
}
/*
* get last X tweets
* @var $tweet int
*/
public function getLastTweets($tweets = 5)
{
//get last x tweets
curl_setopt($this->twitter, CURLOPT_URL,
'http://twitter.com/statuses/user_timeline.json?count=' . $tweets);
curl_setopt($this->twitter, CURLOPT_RETURNTRANSFER, TRUE);
$twitterData = curl_exec($this->twitter);
// convert to array
$twitterDataArray = json_decode($twitterData);
return $twitterDataArray;
}
public function getOutLastTweets($tweets)
{
// get only text out
foreach($this->getLastTweets(10) as $id => $value)
{
echo "tweet $id: " . $value->text . '<br/>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment