How to Implement Login with Twitter PHP : Twitter API Part 1


Twitter is one of the most popular social network used by millions of users. It also allows other websites to implement login with Twitter by using its API. If you are a developer and thinking to add Twitter Login in your website, this tutorial is for you. In this article, I will explain how to use Twitter API with PHP to add Login with Twitter in a website.

Implement Login with Twitter PHP

In this tutorial, I will be using TwiterOAuth library to implement various Twitter functions. Download it here.

I am assuming te root of your website is http://yourdomain and will be using it as a base for all files and requests.

Create Twitter Application


Step 1: Now create a Twitter application here: You need to create a Twitter developer account to access this.

Step 2: Create a new app by entering Name, Description, website and Callback URL. The Callback URL is important because it will process call back request from API. In this, keep: http://yourdomain/oauth.php

Step 3: In Application Settings, check the Access Level. If you also want to tweet, retweet or perform any kind of other similar function, you also need to get the write permission. So, keep the access level to ‘Read and write’.

Step 4: Now go to ‘Keys and Access Tokens’. Here you get API keys and API Secret.

Getting Started

Now create a file config.php and paste the following code.

I hope you know what values to put in the above code for key, secret and callback.

Now you need to create another file Login.php with following code.

Create another file oauth.php with following code

Now create a login.html file to put a login button and link it to the login.php

With the above files,  you can easily setup the login thing and get basic profile info.


Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Leave a Reply

Your email address will not be published. Required fields are marked *


Best custom Android ROMs

10 Best Custom ROMs for Android

How to Identify a Song Playing on a Mac with Siri

How to setup and use night Shift in MacOS