Showing posts with label twitter api. Show all posts
Showing posts with label twitter api. Show all posts

Using the Twitter REST API v1.1 from Azure Mobile Services

Thursday, June 20, 2013

Since the retirement of the Twitter REST API v1, I have been having trouble doing a simple query using the new search API introduced in version 1.1 from Azure Mobile Services because it now requires a signed authentication header in the request using the OAuth 1.0 protocol.

I would suggest reading the tutorial on Schedule recurring jobs in Mobile Services which provides a basic walk through on creating a scheduled job in Azure Mobile Services that requests tweets from Twitter and stores it in a table. The reason you should read this tutorial is to gain some background knowledge on the concept for better understanding of my newly devised method of use.

The problem with the [out-dated] tutorial mentioned above is that it still uses version 1 of the recently depreciated Twitter REST API.

Current (old) approach

Here's the code for the scheduler borrowed from the [current] tutorial:

After plenty of research (and failed attempts) on properly signing the request to have Twitter authenticate it using custom code, I realised that Azure Mobile Services is hosted by a NodeJs process and learned that the 'Request'-object comes out-of-the-box with OAuth support.

New (updated) approach

By simply assigning the application's keys and tokens to the OAuth property of the request, it worked like a charm:


Do take note

There are some breaking changes to the API therefor I strongly recommend studying the Twitter API 1.1 documentation. Some of the other changes I had to make to the original code include changing the expected response body property 'results' to 'statuses' as well as the mapping to the.'update' object.

I hope that this saves someone out there somewhere a lot of trouble and time.

Your comments and tweets are welcome. @FanieReynders.

Till next time!

Community

Popular Posts

Archives

Contributors