Need a helping hand to get started with the Twitter OAuth API?
Try these examples to get you going for both single account and multiple user cases.
Introduction to Single User
There is both single account and multiple user cases described here. The left side is for a single account user and the right side details how to deal with the same request for multiple users. The same OAuth library by Jaisen Mathai is used throughout these examples. You will need to download this zip file which contains all the needed files shown in this example.
Consumer & Access Tokens
The consumer and access tokens are provided by Twitter to identify your application and your user when making any form of calls to the API. Any interaction, whether it is a website, command line script or desktop program will use OAuth consumer and access tokens.
To obtain your tokens, sign into dev.twitter.com/apps and click on your application name. If you haven't created an application yet, please see the section 'How to Register an Application' near the bottom of this page.
Make a note of the Consumer Key and Consumer Secret, then click the 'My Access Token' link on the right menu. From this page, make a note of Access Token (oauth_token) and Access Token Secret (oauth_token_secret). You're now ready to actually do something fun.
Your First Interaction
The consumer and access tokens are provided by Twitter to identify your application and your user when making any form of calls to the API. Any interaction, whether it is a website, command line script or desktop program will use OAuth consumer and access tokens.
Open up the file called "verify_credentials.php" in the "single-account" directory. Replace the tokens in the file with your own that you obtained in the first step. You should then have a file that looks similar to the one shown below.
Navigate to the URL where you have saved your file and you should see the resulting page showing something similar to this page.
Things to Remember
Remember that every request that you make to the Twitter API that is rate limited will lower your request total by 1. Every OAuth application user gets 350 requests per hour. Each user is independently rate limited for your application.
OAuth relies on your machine having an accurate clock. Use NTPd or a similar tool to keep your machines clock accurate.
Always encode all strings as UTF-8.


