Simple tutorial and an example of sign in with twitter using php, easy way to create sign in with twitter, full php code download.

How To Create Sign In With Twitter

Using Twitter API and Abraham Twitter OAuth, we will create sign in with twitter easily.

Sign In With Twitter Demo

Live Demo


Firstly, download sign in with twitter PHP script, by Qassim Hassan.


After downloaded script, open config.php file, and enter your twitter API key (consumer key) and API Secret (consumer secret) and your Callback URL, config.php file:


/* By Qassim Hassan, */

$api_key = "xxxx"; // enter your consumer key

$api_secret = "xxxx"; // enter your consumer secret

$callback_url = ""; // enter your callback url, = http://localhost/


How To Get API Key And API Secret

Go to Twitter Apps and create new App:

create twitter app

Now copy your API Key and API Secret:

twitter api keys

Now go back to config.php file, open it and enter your API Key, and API Secret and Callback URL, now sign in with twitter is ready, but if you want to get tweets count or followers count, etc.. use this variables (you will find it in index.php file):

$tweets_count = $user_profile->statuses_count; // get tweets count
$followers_count = $user_profile->followers_count; // get followers count
$following_count = $user_profile->friends_count; // get following count
$likes_count = $user_profile->favourites_count; // get likes count
$url = $user_profile->entities->url->urls[0]->expanded_url; // get user website
$location = $user_profile->location; // get user location
$profile_header_url = $user_profile->profile_banner_url; // get header image link

Read example result if you want.


All user info will be saved in “user_info” SESSION, if you want to create a new connection, for example publish new tweet, do this:

$user_token = $_SESSION['user_info']['oauth_token'];
$user_token_secret = $_SESSION['user_info']['oauth_token_secret'];

$publish_tweet = new TwitterOAuth($api_key, $api_secret, $user_token, $user_token_secret);
$status = "My first tweet using API."; // your tweet text

$tweet = $publish_tweet-&gt;post('statuses/update', array('status' =&gt; $status));
echo $tweet-&gt;text; // read example result:


Do you want to use Twitter API without cURL and without Abraham library? Read this post.

Check more Tutorials of Login with API.