Twitter Example

Twitter has a very thorough API that is well-documented in RAML.

In this example we’ll load and examine your followers list (you’ll need a Twitter account).

First, let’s create a Twitter client:

// Read about the Twitter API at
API.createClient('twitterRestApi', '');

And now let’s authenticate the client. By omitting the parameters to the authenticate method, we’ll use the API Notebook’s default Twitter keys.

//Authenticate client

Now we have an authenticated client for the Twitter API.

We can see the available endpoints by exploring through the Notebook’s typeahead:

//View the available methods by adding a dot after twitterRestApi..

Let’s take a look at your followers:

// Collect the IDs of your followers
followers = twitterRestApi.followers.ids.json.get();

Now followers holds the response to our request.

We asked Twitter for a list of our followers' ids, so let’s take a look at our most recent follower:

//Capture our most recent follower's id
lastFollowerId = followers.body.ids[0];
'Our most recent follower ID is ' + lastFollowerId;

Great! Let’s get some information about this follower.

// Show profile information.
lastFollower ={
user_id: lastFollowerId
// Display screen name.
'Your last follower\'s screenname is ' + lastFollower.body.screen_name;

That’s just the beginning of what you can do with the Twitter API. Fork this notebook to explore it on your own.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub