Created
July 8, 2013 08:15
-
-
Save kikegarcia/5947080 to your computer and use it in GitHub Desktop.
Twitter PHP Class With Oauth for API 1.1
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 | |
/** | |
* Profile controller | |
* Delegates control to profile controllers to seperate the distinct profile features | |
*/ | |
class Twittercontroller { | |
/** | |
* Constructor | |
* @param Object $registry the registry | |
* @param bool $directCall - are we directly accessing this controller? | |
*/ | |
public function __construct( $registry, $directCall=true, $pagid ) | |
{ | |
$this->registry = $registry; | |
$urlBits = $this->registry->getObject('url')->getURLBits(); | |
if( isset( $urlBits[1] ) ) | |
{ | |
switch( isset( $urlBits[1] ) ? $urlBits[1] : '' ) | |
{ | |
default: | |
$this->twitterhome(); | |
break; | |
} | |
} else { | |
$this->twitterhome(); | |
} | |
} | |
/** | |
* Shows the two first messages on a Twitter account | |
* @param int $user the user whose profile we are viewing | |
* @return void | |
*/ | |
private function twitterhome() | |
{ | |
require_once("controllers/twitter/twitteroauth/twitteroauth.php"); //Path to twitteroauth library | |
$twitteruser = "enriquejgcia"; | |
$notweets = 2; // tweets number | |
$consumerkey = ""; | |
$consumersecret = ""; | |
$accesstoken = ""; | |
$accesstokensecret = ""; | |
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { | |
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); | |
return $connection; | |
} | |
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); | |
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets); | |
json_encode($tweets); | |
//var_dump($tweets); | |
$mensaje1 = $tweets[0]->text; | |
$mensaje2 = $tweets[1]->text; | |
$this->registry->getObject('template')->getPage()->addTag( 'mensaje1', $mensaje1 ); | |
$this->registry->getObject('template')->getPage()->addTag( 'mensaje2', $mensaje2 ); | |
$this->registry->getObject('template')->buildFromTemplates( 'twitter.tpl.php' ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment