Posting to twitter from a PHP application

by   SJRANJAN

In this article you can learn how to post a status update to twitter from a PHP application.

posttotwitter3

First you have to create a app in twitter. For that go to https://dev.twitter.com/apps and sign in with your twitter account.

Go to “My applications” and use “Create a new application” option to create a new twitter application. Keep the application access level to “Read and write”. So that we can write to twitter by using this app.

posttotwitter1

[ Note: Twitter app do not allow you to use localhost as domain or call back URL. In this example i have used www.detailsinn.com. ]

posttotwitter2

There are several PHP libraries available for twitter integration. You can find here : https://dev.twitter.com/docs/twitter-libraries#php

In this article i have used Abraham Williams API Library. You can download it here : https://github.com/abraham/twitteroauth

Download the library and grab “twitteroauth” folder and place it in your project folder. Now create index.php and place following code. Replace CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL with your twitter app details.

Now execute the URL. You will be redirected to twitter to authenticate.

posttotwitter4

Once you done it you can see the form by which you can post to twitter.

posttotwitter5

 

Share on :