easy-twitter
A basic Twitter API for Node.js v4.0+. Follow, unfollow, tweet, get infos about a twitter account and more ...
Getting started
When you have installed and include this twitter module, you have to create a new instance:
Requirements
- Node.js v4.0 or more
Installation
npm install easy-twitter --save
Include the module
const TwitterClient = ;//_Create a new Twitter app and get the keys neededconst twitter = consumer_key: "xxxx" consumer_secret: "yyyy" access_token_key: "zzzz" access_token_secret : "aaaa";
Usage
Create a tweet (message)
If you want to tweet a message you can use the method Twitter.tweet()
. This method returns a promise with the message
in parameter when succeed.
var message = 'Hello world !'; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
Create a tweet with image
The first parameter is the message
you want to post and the second parameter is the path
to the image that you want to post.
const message = 'I like Twitter !';const path = '/foo/bar/image.png'; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
Follow a twitter account
You can follow someone with the method follow()
with the name
of the twitter account in parameter. You can pass in parameter the name of the account with or without the '@'.
// Both the variables are correctconst twitterAccount = 'iAmAlphaZz';const secondTwitterAccount = '@iAmAlphaZz'; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
Unfollow a twitter account
The unfollow()
method is used like the follow()
method: you just have to pass in parameter the name of the twitter account.
// Both the variables are correctconst twitterAccount = 'iAmAlphaZz';const secondTwitterAccount = '@iAmAlphaZz'; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
Get the followers of a twitter account
Get the count
(max: 200) followers list of twitterAccount
const twitterAccount = 'iAmAlphaZz';const count = 12; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
The method getFollowersList()
return three datas:
followers
: An array with the account names of the followersfullInfos
: A JSON Object which contains a lot of informations. Here is a link showing the differents informations returned in this object ( look the 'Example Result' : https://dev.twitter.com/rest/reference/get/followers/list)user
: Is the user name of the twitter account you entered in parameter to the method.
Get the friends of a twitter account
Get the count
(max: 200) people from the friend list of twitterAccount
.
Actually, it returns only the count
lasts. The page
parameter will able to choose more precisely.
const twitterAccount = 'iAmAlphaZz';const count = 50;const page = 1; // using promisetwitter ; // using async/awaittry const data = await twitter catch e throw e
The method getFollowersList()
returns:
followers
: An array with the account names of the followersfullInfos
: A JSON Object which contains a lot of informations. Here is a link showing the differents informations returned in this object ( look the 'Example Result' : https://dev.twitter.com/rest/reference/get/friends/list)user
: Is the user name of the twitter account you entered in parameter to the method.page
: Is not yet implemented...
Get the followers count & friends count
// using promisetwitter // using async/awaittry const data = await twitter catch e throw e