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 : 5852  
 
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 AND DEVELOPMENT.

 
 
 

Related Posts

Why businesses need to be familiar with APIs

APIs serve as intermediaries between software, allowing them to communicate with each other and perform various functions like data sharing or processing. APIs provide the protocols, definitions, tools, and other…

How to Track Flight Status in real-time using the Flight Tracker API

The Flight Tracker API provides developers with the ability to access real-time flight status, which is extremely useful for integrating historical tracking or live queries of air traffic into your…

The Payment Request API: Revolutionizing Online Payments (Part 2)

In the first part of this series, we explored the fundamentals of the Payment Request API and how it simplifies the payment experience. Now, let's delve deeper into advanced features…

The Payment Request API: Revolutionizing Online Payments (Part 1)

The Payment Request API has emerged as the new standard for online payments, transforming the way transactions are conducted on the internet. In this two-part series, we will delve into…

How to Send Email from an HTML Contact Form

In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…

Creating simple CSS spinner-loader

In today's article we will show you how to animate a basic loader that spins when some predefined action is defined, such as loading an image. That can be used…

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…

Clicky