How to retrieve a Twitter user timeline using the Twitter API version 1.1 in PHP

There are various PHP Twitter libraries which each have their advantages and disadvantages, however sometimes it is easier to code it yourself rather than learning and working within the limitations of an existing library.

The first step is to create a new Twitter application at https://apps.twitter.com/ (there are various tutorials available online on how to do this). Once you have created your application, your consumer key, consumer secret, access token and access token secret can be used in the below code.