How to update Twitter API from v1 to v1.1

There is a Mobile Optimized version of this page (AMP). Open Mobile Version.

Has your twitter feed stopped working the last couple of days? Well if your using V1 of the Twitter API then there is a very good reason, twitter have now dropped support for V1 of the API and you must update your code to work with V1.1.

Unfortunately you cannot simply change the URL to upgrade, v1.1 of the twitter API brings several new rules, firstly they no longer allow XML, ATOM or RSS – only JSON is supported from now on. The second important change is that all requests will require HTTPS, so your URL must be https://.

The biggest change however is the new OAUTH requirement, most operations now require OAUTH, this means creating a twitter app, connecting to the app and authenticating and then doing your requests. This also means all JavaScript implementations will be impossible as OAUTH requires Server-Side code.

tmhOAuth is a great class which can be used to OAUTH into your twitter app to make your twitter requests, here is an example of how to fetch your user timeline:

require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'YOUR_CONSUMER_KEY',
  'consumer_secret' => 'YOUR_CONSUMER_SECRET',
  'user_token'      => 'A_USER_TOKEN',
  'user_secret'     => 'A_USER_SECRET',
));
 
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array(
  'screen_name' => 'SBTDev'));
$response = $tmhOAuth->response;

You can find some useful examples of Single-User OAuth with Twitter below:

https://dev.twitter.com/docs/auth/oauth/single-user-with-examples

 

Embedded Timelines

A simple solution for those who do not wish to OAuth or dont have a server with server-side language’s is to use “Embedded Timelines”:

https://dev.twitter.com/docs/embedded-timelines

Author: Dean Williams

I'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags:
, , , ,