6. Premium APIs – Helpful tools

6. Premium APIs – Helpful tools


(snapping) – Okay, so we talked about
why the APIs are so cool, how to get signed up, and
some of the differences from the standard APIs. Now let’s dive in and look at
some of the tools you can use to test things out and get
hold of some data snippets as you build out your solution. First, we’re going to look at a command line tool called HTTPie. This is a little bit like cURL and is very simple to use. It’s very configurable,
and it’s supported on all of the major platforms, like Linux, the Mac, and Windows. So let’s go ahead to our terminal and I’ll show you how
I’ve configured HTTPie. I’ve set it to use HTTPS by default, and I’ve also set the security settings. So I’ve added the bearer token header to this configuration file. That’s the bearer token
for the Twitter API. So we can call the API very
simply using a session file, using our 30 day search Tweets endpoint. And with a simple query of
looking for Tweets of London, up to ten results. And here’s our JSON response. That’s ten Tweets which
match the search term, and because I’m using the premium API, it’s got some of those additional
fields we’ve spoken about. That’s a good way to get started. There’s also some GUI
tools that we can use. One very popular tool that
developers use is Postman. It’s free to download. We’re going to demonstrate
an alternative tool called Insomnia, which is also free and available on all the major platforms. Here’s our Insomnia window, and we’re going to set up a query on the 30 day search endpoint. And here we’ve got our JSON
body defining the query that we’re gonna post to the API. Here we’ve set our bearer token. That’s again the secure token we require for calling the API. I’ve configured a couple
of shortcuts here, so I’ve specified my environment name for my 30 day search endpoint and also for my full
archive search endpoint that we’ll us in a moment, and I’ve specified a base url. We’ll go ahead and send that query, and here’s our JSON response. It comes back nicely
formatted, color coded, plenty of data again. ‘Cause we’re in the Paid tier for Premium, we also access to the Counts endpoint. This endpoint will enable us to get simply the counts of Tweets
that match our query on a basis. In this case, we’ve asked for to tell us on a day by day basis. In the case of this query, we can see that for each day, we’ve got
counts being returned, where the number of
times are query matches. Now I’m going to show you
how to add a new request if you’re using Insomnia,
and we’re gonna configure the full archive search endpoint. Create a new post request
and give it a name. And we’re gonna copy some information from our 30 days search
endpoint just for speed here. So we’re gonna paste in our shortcut, changing our environment name to the full archive search environment, which is a different name in my dashboard, and changing the endpoint to specify the full archive search. I also need to add the bearer token, which I’ll go ahead and copy from my other request and paste across. I’ve obscured it for privacy reasons. And then we need to add a JSON body that we’re gonna post to
the API with our query. Lets, again, quickly copy that
across from our 30 day query, but let’s change up the search term. Now we don’t need quite so many results. We can send that off,
and here’s our results. Now Insomnia has a ton of
really useful features. Let’s go back to our 30 day search, and it saved our results
from the previous query, but look down here; you can actually start to use a powerful query language to filter those results. So here I’ve just asked for the Tweet ID of every Tweet in our
result set or we could just ask for just the text
of each of our Tweets. It’s very, very handy. So that’s HTTPie and Insomnia for testing the new Twitter premium APIs. – [Announcer] Follow us @Twitter Devs and on the community forums.
(bass drums and claps)

Tags:

2 thoughts on “6. Premium APIs – Helpful tools”

Leave a Reply

Your email address will not be published. Required fields are marked *