Sign in with Twitter OAuth API Using PHP
In this tutorial we are going to see how to integrate Twitter Oauth Authentication to webapplication using PHP.
Now every webapplication will have this social networks Oauth Authentication (Facebook, Google and Twitter ) to improve comfortness of their users. So users don’t need to create separate login credentials to each application they visit. They will use any one of the social network (Google, Facebook or Twitter ) login credentials to register and login to the webapplication they visit.
Please refer my previous tutorial on
1. Simple User login, Registration and Forget Password using PHP5, jQuery, MySQLi and Bootstrap
2. Login with Google OAuth 2 Using PHP and MySQL
3. Facebook OAuth 2 Login Using PHP
Step 1:
Before continuing our coding part we need to create Twitter Application using twitter app dashboard. To create Twitter App please going to following URL.
Now login with your twitter account login credentials. Once you logged in, you will get following screen.
Now click on Create New App button to continue.
Step 2:
Fill the following filelds to create Twitter Applications like in the images below.
Please select Read and Write Permission in the Permission tab and click on update settings button to update.
Step 3:
Create sample Databse with table using following SQL queries.
Now create config.php file and define application related constants. Once you created Twitter application successfully, you will get Consumer Key (API Key) and Consumer Secret (API Secret). Please note it down.
Please download below source file, and just replace TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET and TWITTER_OAUTH_CALLBACK with your Consumer Key (API Key), Consumer Secret (API Secret) and callback URL. Then upload this to your server. Now it will work successfully.
Note : Callback URL in your config.php must match with Callback URL in the Twitter App settings page. Please select the checkbox option of Allow this application to be used to Signin with Twitter.
Step 4:
Create index.php and include twitteroauth.php and config.php at the top of the file.
Here index.php full script,
Here is User class twitter_login() method which saves twitter OAuth response in database and signin the user to our webapplication.
Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement