Hi,
I was having a problem to use Twitter API with Yii. After trying a lot of things, I came up with this solution.
I hope it will be useful to someone
First:
Download this extension "yiiframework dot com/extension/twitter"
Install as the author say.
Second:
Download the latest version of abraham/twitteroauth "github dot com/abraham/twitteroauth"
In that zip, go to twitteroauth-master/twitteroauth and copy the two files to extensios/yiitwitteroauth
You would be asked to overwrite the files.
Third:
In extensions/twitteroauth/OAuth.php
Find:
if (!class_exists('OAuthException')) {
class OAuthException extends Exception {
// pass
}
}
And replace with:
if(!class_exists('OAuthException',false)){
class OAuthException extends Exception {
// pass
}
}
In your controller find the new action actionIndex and replace
$request_token = $twitter->getRequestToken();
With this:
$callbackurl='YOUR_URL/controller/twitterCallBack'; // this is your callback url!!!!
$request_token = $twitter->getRequestToken($callbackurl);
*: I don’t know how to use your previous configured callbackurl in your config/main.php sorry!
With that done, you can start to make api calls.
So far, I’ve come with this example code and is working (not sure if it’s the best solution).
public function actionSearchtweets(){
if(Yii::app()->session['status']!='verified'){
echo "Error Token no verificado"; // ??
}else{
$token=Yii::app()->session['access_token']['oauth_token']; // previous obtained token
$secret= Yii::app()->session['access_token']['oauth_token_secret']; // previous obtained password
$twitter = Yii::app()->twitter->getTwitterTokened($token,$secret);
$result=$twitter->get('search/tweets', array('q' => "Mendoza")); // api call
print_r($result);
}
}
If you don’t want to make all this by yourself. I have attached my working copy of the extension (Oh I’m a new user, can’t attach a file)