Created
August 13, 2011 03:57
-
-
Save arush/1143464 to your computer and use it in GitHub Desktop.
twitter curl
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 | |
/** | |
* 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