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

Download

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

Usage

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:

<?php

/* By Qassim Hassan, wp-time.com */

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

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

$callback_url = "http://127.0.0.1/sign_in_with_twitter/sign-in.php"; // enter your callback url, http://127.0.0.1/ = 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.

Note

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: https://dev.twitter.com/rest/reference/post/statuses/update

More

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

Check more Tutorials of Login with API.