⚠️ This lesson is retired and might contain outdated information.

Get Info About Twitter Account with Twitter Library for JavaScript

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

In this lesson we will use the twitter client to get the information about the user's name and followers and check the rate limits after the call to the API.

Dimitri Ivashchuk: [0:00] Let's write some query which makes sense. In this case, we want to get the userInfo, const getUserInfo is the function. We make it async. Then, we want to expand try-catch block. In case of error, we want to console.log the error.

[0:25] We pass with our handler as the parameter in an object de-structuring way, and then we get our Twitter client. Here, it's not usedClient but client. Params object is passed to the particular route.

[0:50] In this case, we're passing screen_name and its twitterHandler, and here, just returning the user with an index , which is how Twitter returns the results from this call.

[1:05] Let's do getUserInfo as an export. Then inside of our app, let's do the following. We get const user variable, and then we await getUserInfo. It's already imported from the twitter folder. Then we want to console.log the user, twitterHandler would be mine in this case, divdev_.

[1:42] You see that we have done the call. This is the information about my particular account. Let's just get the name and the followers count. Is it followers count? We just look at an object, which would be { user: user.name, followers: user.followers_count }. Let's console.log this.

[2:24] Then you see that we have Dimitri here and my followers count. You also notice that the remaining count of the users/lookup query is now 899. That's because we have done the query here. If we are swapping these places, then we will get the correct rate limit after each call. Let's save.

[2:57] You see that we have now made another call, and we have 897, of course, until this timestamp resets. That's it about Twitter API. Have fun with it.

egghead
egghead
~ 8 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today