Twitter REST API Integration On PHP

Twitter exposes its data via an Application Programming Interface (API) to read and write Twitter data. An application program interface (API) is code that allows two software programs to communicate with each other. We can connect with Twitter REST APIs with any language like PHP, Java, Node.JS, etc.., to built application with Twitter data. Here, In this article we are going to use PHP to connect with Twitter REST API.

Create Twitter Application

  • Go to Twitter Application Management and login using your twitter account.
  • Now, Create a New Application by clicking Create New App button.
  • Enter your Application Name, Description, Website, Callback URL(Optional) and then confirm your application by accepting Twitter Developer Agreement.
  • Submit the form by clicking the Create your Twitter Application
  • After creating the Application you will find the details of Consumer API Key, Consumer API Secret, Owner, Owner ID, Access Token and Access Token Secret

Integrate Twitter With PHP Using REST APIs

REST APIs provide programmatic access to read and write Twitter data. Author a new Tweet, read author profile and follower data, and more. The REST API identifies Twitter applications and users using OAuth; responses are available in JSON.

You can view or download the source code on GitHub. You need to add your application details like Consumer API Key, Consumer API Secret, Owner, Owner ID, Access Token and Access Token Secret to configure your API with program.

Sample program is for statuses/user_timeline to get most recent Tweets posted by the user(twitter feed). I also used pagination based on max_id, since_id (Working with Timelines), So that you can get the required number of tweets per page. Sample code is written as service for mobile application, Hence I return it as JSON format. You can test this code with Postman for pagination. Please leave your valuable comments/suggestions/feedback on below comment box if any. Also contact me if your facing any issues on this code.

Thank You !!


SIVA SANKAR, Working as a Software Engineer, Blogging is my hobby. I completed my Bachelors of Engineering (Computer Science Engineering) in Chennai, India. and my Master of Engineering (Embedded System Technologies) in Tamilnadu, India.

6 thoughts on “Twitter REST API Integration On PHP

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.