2017 © Pedro Peláez
 

yii2-extension yii2-twitter

Yii2 extension to the Twitter API

image

richweber/yii2-twitter

Yii2 extension to the Twitter API

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

Yii2 extension to the Twitter API

Twitter Oauth Library, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

$ php composer.phar require richweber/yii2-twitter "dev-master"

or add, (*4)

"richweber/yii2-twitter": "dev-master"

to the require section of your composer.json file., (*5)

Usage

Component Configuration

'components' => [
    ...
    'twitter' => [
        'class' => 'richweber\twitter\Twitter',
        'consumer_key' => 'YOUR_TWITTER_CONSUMER_KEY',
        'consumer_secret' => 'YOUR_TWITTER_CONSUMER_SECRET',
        'callback' => 'YOUR_TWITTER_CALLBACK_URL',
    ],
    ...
],

Authenticate application

twitter->getTwitter();
        $request_token = $twitter->getRequestToken();
 
        //set some session info
        Yii::$app->session['oauth_token'] = $token = $request_token['oauth_token'];
        Yii::$app->session['oauth_token_secret'] = $request_token['oauth_token_secret'];
 
        if ($twitter->http_code == 200){
            //get twitter connect url
            $url = $twitter->getAuthorizeURL($token);
            //send them
            return $this->redirect($url);
        } else {
            //error here
            return $this->redirect(Url::home());
        }
    }
}
?>

Callback action

session['oauth_token'] !== $_REQUEST['oauth_token']) {
            Yii::$app->session['oauth_status'] = 'oldtoken';
        }
 
        /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
        $twitter = Yii::$app->twitter->getTwitterTokened(Yii::$app->session['oauth_token'], Yii::$app->session['oauth_token_secret']);   
 
        /* Request access tokens from twitter */
        $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']);
 
        /* Save the access tokens. Normally these would be saved in a database for future use. */
        Yii::$app->session['access_token'] = $access_token;
 
        /* Remove no longer needed request tokens */
        unset(Yii::$app->session['oauth_token']);
        unset(Yii::$app->session['oauth_token_secret']);
 
        if (200 == $twitter->http_code) {
            /* The user has been verified and the access tokens can be saved for future use */
            Yii::$app->session['status'] = 'verified';
 
            //get an access twitter object
            $twitter = Yii::$app->twitter->getTwitterTokened($access_token['oauth_token'],$access_token['oauth_token_secret']);
 
            //get user details
            $twuser= $twitter->get("account/verify_credentials");
            //get friends ids
            $friends= $twitter->get("friends/ids");
            //get followers ids
            $followers= $twitter->get("followers/ids");
            //tweet
            $result=$twitter->post('statuses/update', ['status' => "Tweet message"]);
 
        } else {
            /* Save HTTP status for error dialog on connnect page.*/
            //header('Location: /clearsessions.php');
            return $this->redirect(Url::home());
        }
    }
}
?>

License

yii2-twitter is released under the BSD 3-Clause License. See the bundled LICENSE.md for details., (*6)

The Versions

25/10 2016

dev-master

9999999-dev https://github.com/RichWeber/yii2-twitter

Yii2 extension to the Twitter API

  Sources   Download

BSD-3-Clause

The Requires

 

api yii2 twitter

25/10 2016

1.0.2

1.0.2.0 https://github.com/RichWeber/yii2-twitter

Yii2 extension to the Twitter API

  Sources   Download

BSD-3-Clause

The Requires

 

api yii2 twitter

12/02 2015

1.0.1

1.0.1.0 https://github.com/RichWeber/yii2-twitter

Yii2 extension to the Twitter API

  Sources   Download

BSD-3-Clause

The Requires

 

api yii2 twitter

11/02 2015

1.0.0

1.0.0.0 https://github.com/RichWeber/yii2-twitter

Yii2 extension to the Twitter API

  Sources   Download

BSD-3-Clause

The Requires

 

api yii2 twitter