1.0.23 โ€ข Published 2 years ago

v2-twitter v1.0.23

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Twitter V2

v2 codecov Sonarcloud Status

Twitter api, using V2, for use, create new instance of api, no parameter is necessary, but if you don't pass BearerToken, the others params ConsumerKey, ConsumerSecret, AccessToken, AccessSecret are necessary, but you can pass all parameters

import TwitterApi from 'v2-twitter'

const twitter = new TwitterApi({
  BearerToken: "",
  ConsumerKey: "",
  ConsumerSecret: "",
  AccessToken: "",
  AccessSecret: "",
});

Get An User By Username

For get all user information's:, all parameters and fields can be consulted here

twitter
  .getUserByUsername("TwitterDev", ['profile_image_url'])
  .then((data) => console.log(data));

// {
//     "data": {
//         "id": "2244994945",
//         "name": "Twitter Dev",
//         "username": "TwitterDev"
//     }
// }

Get Many Users For Username

For get all user information's for many users:, all parameters and fields can be consulted here

twitter
  .getUsersByUsername(["TwitterDev"], ['profile_image_url'])
  .then((data) => console.log(data));

// {
//     "data": [
//         {
//             "id": "2244994945",
//             "name": "Twitter Dev",
//             "username": "TwitterDev"
//         }
//     ]
// }

Get User For UserId

For get all user information's by user id:, all parameters and fields can be consulted here

twitter
  .getUserById('2244994945', ['profile_image_url'])
  .then((data) => console.log(data));

// {
//     "data": {
//         "id": "2244994945",
//         "name": "Twitter Dev",
//         "username": "TwitterDev"
//     }
// }

Get Many Users For UserId

For get all user information's by user id for many users:, all parameters and fields can be consulted here

twitter
  .getUsersById(['2244994945'], ['profile_image_url'])
  .then((data) => console.log(data));

// {
//     "data": [
//         {
//             "id": "2244994945",
//             "name": "Twitter Dev",
//             "username": "TwitterDev"
//         }
//     ]
// }

Get Tweet By Id

For get tweet data for tweet id: all parameters and fields can be consulted here

twitter
  .getSingleTweet('2244994945', { tweet: ['text', 'id'] })
  .then((data) => console.log(data));

// {
//     "data": {
//         "id": "1461381489115947010",
//         "text": "Thereโ€™s so much information in Tweets that @SPDJIndices built a stock index around them.\n\nIntroducing the S&P 500 Twitter Sentiment Index, now measuring conversations & $cashtags on the top positively talked about S&P 500 companies. #YourVoiceYourIndex ๐Ÿ‘‡\n\nhttps://t.co/8aKDXpc94r https://t.co/jiIrBDQb2g"
//     }
// }

Get Many Tweets by Id

For get tweet data for many tweets id: all parameters and fields can be consulted here

twitter
  .getMultipleTweets('2244994945', { tweet: ['text', 'id'] })
  .then((data) => console.log(data));

// {
//     "data": [
//         {
//             "id": "1461381489115947010",
//             "text": "Thereโ€™s so much information in Tweets that @SPDJIndices built a stock index around them.\n\nIntroducing the S&P 500 Twitter Sentiment Index, now measuring conversations & $cashtags on the top positively talked about S&P 500 companies. #YourVoiceYourIndex ๐Ÿ‘‡\n\nhttps://t.co/8aKDXpc94r https://t.co/jiIrBDQb2g"
//         }
//     ]
// }

Get User Timeline By UserId

For get timeline of user by user id: all parameters and fields can be consulted here

twitter
  .getTimelineByUserId('2244994945', { tweet: ['text', 'id'] })
  .then((data) => console.log(data));

// {
//     "data": [
//         {
//             "id": "1461381489115947010",
//             "text": "Thereโ€™s so much information in Tweets that @SPDJIndices built a stock index around them.\n\nIntroducing the S&P 500 Twitter Sentiment Index, now measuring conversations & $cashtags on the top positively talked about S&P 500 companies. #YourVoiceYourIndex ๐Ÿ‘‡\n\nhttps://t.co/8aKDXpc94r https://t.co/jiIrBDQb2g"
//         }
//     ],
//     "meta": {
//         "oldest_id": "1460323748788072449",
//         "newest_id": "1461381489115947010",
//         "result_count": 10,
//         "next_token": "7140dibdnow9c7btw3z3al3eejvt8u5twuupa4vswh54p"
//     }
// }

Create new Tweet

๐Ÿšจ For post/create new Tweet is necessary oauth login and write access ๐Ÿšจ For create new tweet: all parameters and fields can be consulted here

twitter
  .createTweet('2244994945', { tweet: ['text', 'id'] })
  .then((data) => console.log(data));

// {
//     "data": {
//         "id": "1461897194655600647",
//         "text": "Hello!"
//     }
// }

Delete Tweet by Id

๐Ÿšจ For delete Tweet is necessary oauth login and write access ๐Ÿšจ For delete tweet:

twitter
  .deleteTweet('2244994945')
  .then((data) => console.log(data));

// {
//     "data": {
//         "deleted": true
//     }
// }

Get Followers By UserId

For get all followers for user by id: all parameters and fields can be consulted here

twitter
  .getFollowersById('2244994945', { max:10 })
  .then((data) => console.log(data));

// {
//     "data": [
//         {
//             "id": "2244994945",
//             "name": "Twitter Dev",
//             "username": "TwitterDev"
//         }
//     ],
//     "meta": {
//         "result_count": 100,
//         "next_token": "76NGG1H6J79HEZZZ"
//     }
// }

Follow User

๐Ÿšจ For follow user is necessary oauth login and write access ๐Ÿšจ Your id on the left, and id to follow in right For follow a user:

twitter
  .followUserId('2244994945', '2244994945')
  .then((data) => console.log(data));

// {
//     "data": {
//         "following": true,
//         "pending_follow": false
//     }
// }

Unfollow User

๐Ÿšจ For unfollow user is necessary oauth login and write access ๐Ÿšจ Your id on the left, and id to unfollow in right For unfollow a user:

twitter
  .unfollowUserId('2244994945', '2244994945')
  .then((data) => console.log(data));

// {
//     "data": {
//         "following": false
//     }
// }

Follow User By Username

๐Ÿšจ For this method necessary oauth login, bearer token and write access ๐Ÿšจ Your username on the left, and username to follow in right For unfollow a user by username:

twitter
  .followUsername('TwitterDev', 'TwitterDev')
  .then((data) => console.log(data));

// {
//     "data": {
//         "following": true,
//         "pending_follow": false
//     }
// }

Unfollow User By Username

๐Ÿšจ For this method necessary oauth login, bearer token and write access ๐Ÿšจ Your username on the left, and username to unfollow in right For unfollow a user by username:

twitter
  .unfollowUsername('TwitterDev', 'TwitterDev')
  .then((data) => console.log(data));

// {
//     "data": {
//         "following": false
//     }
// }

V1.1 API Support

This module does not support previous versions of the Twitter API, however it works well with the following V1.1 modules

NPM

NPM

More methods will come...
1.0.23

2 years ago

1.0.24

2 years ago

1.0.22

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.14

2 years ago

1.0.10

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.1

2 years ago