What you need is 5 php files (you can probably have fewer, but it is easier to understand if we have 5 files):
- index.php - this is the main file - or your web service
- login_to_twitter.php - send information to Twitter
- twittersecret.php - secret parameters from dev.twitter.com
- login_from_twitter.php - receive information from Twitter
- logout.php - if the user wants to logout
The main point of this file is to display a login-with-twitter-button if the user has not signed in with Twitter - or display the @name of the user and a logout-button if the user has signed in with Twitter
The main point of this file is to send data to Twitter so the user can sign in to Twitter and then be redirected back to your page. What you need to do to make this work is to:
- Download the three files: EpiCurl.php, EpiOAuth.php, and EpiTwitter.php from: github.com/jmathai/twitter-async/
- Register your application at: dev.twitter.com/
- The callback URL is in this case: www.yoursite.com/_include/login/login_from_twitter.php
- You also need to create a file with the $consumer_key and $consumer_secret with data from dev.twitter.com
These are personal and obtained when you have created the application at dev.twitter.com
This is the page you come to after you have signed in with Twitter at twitter.com. The point of this page is the obtain the twitter_id and the @name. If you want so save data about the user in a database, you should use the twitter_id. If you use the @name, the user may change it and mess up your database. One can't change the twitter_id.
One problem with this is that you have to upload everything to your server if you want to test if everything is working. Using something like XAMPP will not work!
If you would like to read more about how to sign in with Twitter and social login, you can use the following resources: