If you have been looking for a simple twitter library in PHP that will take care of the dirty OAuth handshakes for you, then my friend, you have come to the right place!
- Normalize your URL and prepare it to be signed
- Create your HMAC-SHA1 signature needed for OAuth
- Acquire request and access tokens, and authorize your users with Twitter
- Allow your users to update their statuses without leaving your site!
all by using three simple function calls!
UPDATE : You can now download my Twitter API class here
<?php require_once('Tweeter.php'); //INTIALIZE YOUR CONFIG AND CREATE YOUR CLASS $config['key'] = 'ConsumerKey'; //Consumer key provided by twitter $config['secret'] = 'ConsumerSecret&'; //Consumer secret provided by Twitter - The ampersand at the end is intentional $twitter = new Tweeter($config); $twitter->get_request_token($twitter->request_token_url); //Request your "request_token" ?>
Remember we mentioned our call-back function? (refer back to your class notes for Tweeter.php)
Below is the file I chose for my call-back re-direct:
<?php session_start(); require_once('Tweeter.php'); $oauth_verifier = $_GET['oauth_verifier']; $oauth_token = $_GET['oauth_token']; $twitt = unserialize($_SESSION['twitt']); $twitt->verifier = $oauth_verifier; $twitt->get_access_token(); //Use the token and verifier to acquire the access token - Almost there! print "Done"; $twitt = unserialize($_SESSION['twitt']); $twitt->tweet_msg('last tweet of the day.'); ?>
That’s all folks. Tell me how much you love it. Tell me how much you hate it. Questions? Answers!