How to Create a Twitter Proxy For Mobile Development

How to create a Twitter proxy for mobile development
by Janeth Kent Date: 06-12-2013 twitter API proxy programming mobile


Since Twitter switched over to version 1.1 of the Twitter API, the first cause of developers headaches is the move to enforce OAuth for every API request, the second guilt - rate limiting - is responsible for drastic restructuring of existing code.

The new rate limitations are pretty strict, most requests are limited to 1 request per minute with some increased to 12 per minute, and the highest for app level requests topping out at 20-30 per minute.

So, you have two choices:

  1. Force each user to authenticate with their own twitter credentials

  2. Authenticate the app and cache the requests to avoid the rate limit

Option 1 is not really viable for a website but is a possibility for mobile apps.

Option 2 is going to be the more common option for a wide range of use cases.

A cache strategy

We’are going to propose an option that we’ve used many times with success since the move to API v1.1 - a server side Twitter API proxy with caching.

The basic idea is that you create a server side program to act as a go-between (or proxy) for your app and the Twitter API.

This proxy will be responsible for authenticating the requests as well as maintaining a cache of the responses.

To maintain the cache, the proxy checks to see when the cache file was last updated. If the time that has elapsed exceeds the threshold (say 1 minute), a request is performed by the proxy to the Twitter API and the response will be used to rebuild the cache.

Then, as your mobile app or website makes requests to your proxy, it is always served a response from the cache, which means that the response will not only be immune to rate-limits, it will also be instantaneous.

An added bonus to this proxy strategy is that it re-enables access to the Twitter API from JavaScript which, on its own, can no longer be used to access the Twitter API.

Source Code

The code can be downloaded from GitHub by visiting the twitter-api-php-cached page (credit  Matthew Mombrea's).

This version of the code only offers a single API method, one which reads the timeline of the authenticated user. The cache is a flat file which also stores the update timestamp on the first line. This package is meant to serve as a starting point for your Twitter proxy service, you’ll no doubt want to add additional API calls and possibly move your cache to something in memory like memcache.

To get started, read through the simple setup instructions in the ReadMe and you’ll be retrieving your cached tweets in no time.

 
by Janeth Kent Date: 06-12-2013 twitter API proxy programming mobile hits : 4025  
 
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN END DEVELOPMENT.

 
 
 

Related Posts

Django vs. Laravel: Market Share Comparison

There are two leading frameworks in the web development segment: Django and Laravel. In this article, we prepared a Django and Laravel comparison focusing on their market share so that…

How to make the website's dark mode persistent with Local Storage, CSS and JS

Recently we wrote about how to do a switchable alternative color mode or theme, a very useful and popular feature to websites. Today’s article is going to be about how…

A Java approach: While loop

Hello everyone and welcome back! After having made a short, but full-bodied, introduction about cycles, today we are finally going to see the first implementations that use what we have called…

Making AJAX requests to a REST API using vanilla JavaScript and XHR

Imagine you just build your first static web page and you would like to add some functionality to make it more attractive and generally more usable. Perhaps you would like…

Dark Mode on website using CSS and JavaScript

In today’s article we are going to learn how to build pretty much standard these days on the web pages and that is the alternative color mode and switching between…

A Java approach: The Cycles - Introduction

Hello everyone and welcome back! Until now, we have been talking about variables and selection structures, going to consider some of the fundamental aspects of these two concepts. Theoretically, to…

JavaScript: Spread and Rest operators

In today’s article we are going to talk about one of the features of the ES6 version(ECMAScript 2015) of JavaScript which is Spread operator as well as Rest operator. These features…

A Java approach: boolean variables

The previous time, we talked extensively about Boolean variables, trying to outline the main operations that can be carried out at a practical level.  Of all the cases examined, we have…

A Java approach: condtional structures

Hello everyone and welcome back! The previous times we have introduced the concept of variable, trying to define some basic concepts about it.  However, some situations suggest that the concept of…

Hashmap: Overflow Lists

In this short series of articles we will go to see how it is possible to create the Hashmap data structure in C. In the implementation we're going to use the…

A Java approach: variables - use case

Hello all friends and welcome back! After the introduction made on the variables, we try to analyse some critical issues that may arise in quite common situations. Let's start by analysing…

Data Scraping and Data Crawling, what are they for?

Right now we are in an era where big data has become very important. At this very moment, data is being collected from millions of individual users and companies. In…

We use our own and third-party cookies to improve our services, compile statistical information and analyze your browsing habits. This allows us to personalize the content we offer and to show you advertisements related to your preferences. By clicking "Accept all" you agree to the storage of cookies on your device to improve website navigation, analyse traffic and assist our marketing activities. You can also select "System Cookies Only" to accept only the cookies required for the website to function, or you can select the cookies you wish to activate by clicking on "settings".

Accept All Only sistem cookies Configuration