From the course: Calling REST APIs with Java
Twitter API - Java Tutorial
From the course: Calling REST APIs with Java
Twitter API
- [Instructor] The next iteration of our course project builds integration with Twitter's REST API to listen for tweets made about specific topics. The Twitter API is one of the most popular public APIs available. It has a long history that dates back to its release in 2006. Today, the Twitter API is just part of the Twitter developer platform. This platform features an ads API, tools for embedding content into websites and an experimental lab. What draws developers to the Twitter API is the sheer volume of data that can be analyzed and listened to for specific events. The Twitter platform has an estimated 330 million active users per month. People across the world make 200 billion tweets per year. That means roughly every second, there are 6,000 tweets. Think about all those tweets that just occurred. Those tweets tap into the hearts and minds of people around the world, creating a stream of information that researchers, scientists, businesses and governments can analyze for a variety of purposes. The Twitter API is the gateway for developers who want to unlock that stream of information to build new applications and capabilities. There are two versions of the API and three different access tiers. We'll be working with Twitter, API V2 which is currently available for early access. At the moment the version two API is limited to information regarding tweets and users. However, the product roadmap targets capabilities like trends and time series metrics for future delivery. Let's just do a quick pass within the documentation to learn more about the API. So from the developer platform, head into the Docs and then dive into the Twitter API. And then on the left-hand sidebar you're going to see the two objects that are available. One is Tweets, one's Users. Expand Tweets and head into the Search Tweets section. Now in the Docs, most of the important information for us is within the API reference. So let's go there and then I'm going to dive into the recent search endpoint. Now, we're not going to talk about recent search, we're more going to focus on some global aspects of the Twitter API. So, first you'll see the domain for the API, it's api.twitter.com and you can see they specify the version in the path to an endpoint. And then they just finish off with the remainder of the path. The API is protected using OAuth two, so that's the security scheme, and that's going to require us to provide a bearer token in our requests. Another thing I want to highlight is the rate limiting. So providers of APIs will often limit clients to a number of requests over a specific window. Here they've chosen to allow 450 requests within a 15-minute window. They do this to prevent an abusive client from making the API unavailable to other clients. So, our client isn't going to have that problem because of the number of calls we'll make. But if you have a different usage scenario just be aware of this. Alright, another thing I want to point out, if we look at the query parameters you'll see several that have this field suffix, you can see two here. And this field suffix is really neat because it allows us to shape the response that gets sent back to our client. Let's scroll down to talk a little bit more about this. So here's an example response and it's the base tweet object, and it only contains two properties, id and the text of the tweet. Now, we can use those parameters that have the field suffix to mold what that JSON looks like. So here in the optional fields tab you can see that we're able to add additional properties to the tweet. So it's really flexible in that you control what data gets sent back to you in the JSON in the response body. Alright, let's go take a look at one more thing. So over on the sidebar, click on filtered stream and we're going to talk about the filtered stream here at a high level. The filtered stream capability works a little bit differently than your typical request and response scenario with most API calls. Instead of making a request and receiving a response, the stream endpoint is event-based. It pushes specific tweets to a client based upon a set of roles that are established for the client through a roles endpoint. So, you can see that here. This endpoint is used to establish or delete a role. All the client's roles are managed through this endpoint and you essentially establish key words or different query-like predicates that determine what tweets get sent in your stream. Once a client has established these roles, they can then connect to the stream using this endpoint and sending an HTTP GET. At that point, Twitter is going to start pushing tweets into their stream, it's pretty neat. Twitter's API is very popular amongst developers because of the amount of activity on the platform that can be accessed and analyzed for many purposes. We'll get hands-on with these APIs in upcoming lessons so you can experience the power of the Twitter API.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Twitter API5m 56s
-
(Locked)
Twitter API registration and security7m 34s
-
(Locked)
Calling APIs with Spring2m 15s
-
(Locked)
Spring WebClient7m 44s
-
(Locked)
Streaming APIs1m 39s
-
(Locked)
Calling Twitter Streaming API with Spring WebClient8m 21s
-
(Locked)
Challenge: Twitter API3m 22s
-
(Locked)
Solution: Twitter API7m 6s
-
-
-