How to login with Yii2 through twitter account

Active3 hr before
Viewed126 times

5 Answers


Yii2: How to create/develop a new extension using Composer locally without version control or Git,First, make sure you add the official yii2-authclient extension to your application (follow its instructions for installation).,This tutorial is not about allowing users to sign into your application by using any of the OAuth providers available with the official yii2-authclient extension, it is about how to interact with your Twitter account, the one you set for your Yii2 app to promote your site, using the Single Access Token technique. ,We are set, with your the extension installed and the Consumer Key, Consumer Secret, Access Token and Access Token Secret, its time to test if you are able to communicate with Twitter.

Configure the "params" section of your application configuration file to hold, your Twitter application keys information:

// ...
'params' => [
   'twitterApiKey' => 'YOUR CONSUMER KEY',
   'twitterApiSecret' => 'YOUR CONSUMER SECRET',
   'twitterAccessToken' => 'YOUR ACCESS TOKEN',
   'twitterAccessTokenSecret' => 'YOUR ACCESS TOKEN SECRET'
// ...

Done, lets test it...

use yii\ authclient\ clients\ Twitter;
use yii\ authclient\ OAuthToken;

// create your OAuthToken 
$token = new OAuthToken([
   'token' => Yii::$app - > params['twitterAccessToken'],
   'tokenSecret' => Yii::$app - > params['twitterAccessTokenSecret']

// start a Twitter Client and configure your access token with your
// recently created token
$twitter = new Twitter([
   'accessToken' => $token,
   'consumerKey' => Yii::$app - > params['twitterApiKey'],
   'consumerSecret' => Yii::$app - > params['twitterApiSecret']

var_dump($twitter - > api('statuses/home_timeline.json', 'GET'));
load more v

Meta Stack Overflow , Stack Overflow Public questions & answers , Stack Overflow help chat ,Thanks for contributing an answer to Stack Overflow!

I am following the yii2-user guide, and I succeed to login through a facebook account. Now i want to login through a twitter account and my

'consumerKey' => 'h5XFtvRVSxxxxxxxxxxxxx',
'consumerSecret' => 'Zb6lCescDoatl1thwGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
load more v

For this tutorial, I'll walk you through adding Twitter and Google authentication.,The Yii2-User login page displays its Connect widget for AuthClient services on the sign-in page—notice the Google and Twitter icons at the bottom of the page:,Then it will take you to the Connect registration form in our application—this page is also provided by Yii2-User:, Guide to AuthClient Extension for Yii 2

First, we need to add the AuthClient library to composer.json:

"minimum-stability": "stable",
"require": {
   "php": ">=5.4.0",
   "yiisoft/yii2": "*",
   "yiisoft/yii2-bootstrap": "*",
   "yiisoft/yii2-swiftmailer": "*",
   "dektrium/yii2-user": "0.8.2",
   "stichoza/google-translate-php": "~2.0",
   "yiidoc/yii2-redactor": "2.0.0",
   "yiisoft/yii2-authclient": "*"
load more v

Yii2 extension to the Twitter API , Yii2 extension to the Twitter API ,yii2-twitter is released under the BSD 3-Clause License. See the bundled for details.,Twitter Oauth Library

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

A User table will store the users details. For this tutorial we’ll keep the columns/fields to a minimum to focus on OTP Authentication. Use the following MySQL Command to create a table named tbl_user.,OTP field – Here the user will enter the received OTP ,Note: If you are on a Twilio trial account the numbers you can send an SMS to are limited to verified numbers only. For more info check this page.,The otp field in the table stores the random OTP generated for a phone number, and otp_expire contains the time (Unix timestamp format) up to which an otp is valid for.

< ? php

return [
   'class' => 'yii\db\Connection',
   'dsn' => 'mysql:host=localhost;dbname=twilio_sms',
   'username' => 'root',
   'password' => '',
   'charset' => 'utf8',

   // Schema cache options (for production environment)
   //'enableSchemaCache' => true,
   //'schemaCacheDuration' => 60,
   //'schemaCache' => 'cache',
load more v

Other "twitter-login" queries related to "How to login with Yii2 through twitter account"