easy-twitter
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "easy-twitter", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A simple twitter module", | ||
"main": "index.js", | ||
"keywords": ["twitter", "simple", "api", "node", "easy", "easy-twitter", "pandazaur"], | ||
"keywords": [ | ||
"twitter", | ||
"simple", | ||
"api", | ||
"node", | ||
"easy", | ||
"easy-twitter", | ||
"pandazaur" | ||
], | ||
"scripts": { | ||
@@ -8,0 +16,0 @@ "test": "node ./test/test.js" |
177
README.md
# easy-twitter | ||
A basic Twitter API for Node.js / io.js written in ECMAScript 6. | ||
A basic Twitter API for Node.js v4.0+. | ||
Follow, unfollow, tweet, get infos about a twitter account and more ... | ||
@@ -8,6 +8,4 @@ | ||
#### Introduction | ||
To use this module, you need to use either: | ||
- Node.Js v4.0.0. | ||
- Io.js v3.3.0 | ||
#### Requirements | ||
- Node.js v4.0 or more | ||
@@ -20,17 +18,10 @@ #### Installation | ||
#### Launch your application | ||
You need to use `use_strict` parameter: | ||
```bash | ||
node --use_strict your-app.js | ||
``` | ||
#### Include the module | ||
```javascript | ||
var TwitterClient = require('easy-twitter'); | ||
const TwitterClient = require('easy-twitter'); | ||
//_Create a new Twitter app and get the keys needed | ||
var twitter = new TwitterClient({consumer_key: "xxxx", | ||
const twitter = new TwitterClient({consumer_key: "xxxx", | ||
consumer_secret: "yyyy", | ||
access_token_key: "zzzz", | ||
access_token_key: "zzzz", | ||
access_token_secret : "aaaa"}); | ||
@@ -45,11 +36,21 @@ ``` | ||
var message = 'Hello world !'; | ||
// using promise | ||
twitter.tweet(message) | ||
.then(function(data) { | ||
//_Successfully tweet the message | ||
console.log('Posted the tweet:' + data.tweet); | ||
}) | ||
.catch(function(err) { | ||
//_If failed to tweet | ||
console.log(err.error); | ||
}); | ||
.then(data => { | ||
// Successfully tweet the message | ||
console.log('Posted the tweet:' + data.tweet); | ||
}) | ||
.catch(err => { | ||
// Failed to tweet | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.tweet(message) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
@@ -61,12 +62,20 @@ | ||
```javascript | ||
var message = 'I like Twitter !'; | ||
var path = '/foo/bar/image.png'; | ||
const message = 'I like Twitter !'; | ||
const path = '/foo/bar/image.png'; | ||
// using promise | ||
twitter.uploadMedia(message, path) | ||
.then(function(data) { | ||
.then(data => { | ||
console.log('Tweeted the message: ' + data.message); | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.uploadMedia(message, path) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
@@ -78,13 +87,21 @@ | ||
```javascript | ||
//_Both the variables are correct | ||
var twitterAccount = 'iAmAlphaZz'; | ||
var secondTwitterAccount = '@iAmAlphaZz'; | ||
// Both the variables are correct | ||
const twitterAccount = 'iAmAlphaZz'; | ||
const secondTwitterAccount = '@iAmAlphaZz'; | ||
// using promise | ||
twitter.follow(twitterAccount) | ||
.then(function(data) { | ||
console.log('You\'re now following :' + data.user); | ||
.then(data => { | ||
console.log('You\'re now following :' + data.user); | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.follow(twitterAccount) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
@@ -96,24 +113,33 @@ | ||
```javascript | ||
//_Both the variables are correct | ||
var twitterAccount = 'iAmAlphaZz'; | ||
var secondTwitterAccount = '@iAmAlphaZz'; | ||
// Both the variables are correct | ||
const twitterAccount = 'iAmAlphaZz'; | ||
const secondTwitterAccount = '@iAmAlphaZz'; | ||
// using promise | ||
twitter.unfollow(twitterAccount) | ||
.then(function(data) { | ||
.then(data => { | ||
console.log('You\'re now following :' + data.user); | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.unfollow(twitterAccount) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
#### Get the followers of a twitter account | ||
Get the `count` (max: 200) followers list of `twitterAccount` | ||
Get the `count` (max: 200) followers list of `twitterAccount` | ||
```javascript | ||
var twitterAccount = 'iAmAlphaZz'; | ||
var count = 12; | ||
const twitterAccount = 'iAmAlphaZz'; | ||
const count = 12; | ||
// using promise | ||
twitter.getFollowersList(twitterAccount, count) | ||
.then(function(data) { | ||
.then(data => { | ||
// data.followers : Array of the followers name ( 12 followers because count = 12) | ||
@@ -123,9 +149,16 @@ // data.fullInfos : More infos below | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.getFollowersList(twitterAccount, count) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
The method `getFollowersList()` return three datas: | ||
- `followers`: An array with the account names of the followers | ||
The method `getFollowersList()` return three datas: | ||
- `followers`: An array with the account names of the followers | ||
- `fullInfos`: 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) | ||
@@ -136,11 +169,13 @@ - `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 followers list of `twitterAccount`. | ||
Actually, it returns only the lasts. The `page` parameter will able to choose more precisely. | ||
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. | ||
```javascript | ||
var twitterAccount = 'iAmAlphaZz'; | ||
var count = 50; | ||
const twitterAccount = 'iAmAlphaZz'; | ||
const count = 50; | ||
const page = 1; | ||
twitter.getFollowersList(twitterAccount, count, page) | ||
.then(function(data) { | ||
// using promise | ||
twitter.getFriendsList(twitterAccount, count, page) | ||
.then(data => { | ||
// data.friends : Array of the friends name ( 50 followers because count = 50) | ||
@@ -150,9 +185,16 @@ // data.fullInfos : More infos below | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}); | ||
// using async/await | ||
try { | ||
const data = await twitter.getFriendsList(twitterAccount, count, page) | ||
} catch (e) { | ||
throw e | ||
} | ||
``` | ||
The method `getFollowersList()` return three datas: | ||
- `followers`: An array with the account names of the followers | ||
The method `getFollowersList()` returns: | ||
- `followers`: An array with the account names of the followers | ||
- `fullInfos`: 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) | ||
@@ -162,6 +204,8 @@ - `user`: Is the user name of the twitter account you entered in parameter to the method. | ||
#### Get the followers count & friends count | ||
#### Get the followers count & friends count | ||
```javascript | ||
// using promise | ||
twitter.getCounts('iAmAlphaZz') | ||
.then(function(data) { | ||
.then(data => { | ||
// data.user : In this case 'iAmAlphaZz' | ||
@@ -171,5 +215,12 @@ // data.followersCount : Count of people following the account in parameter | ||
}) | ||
.catch(function(err) { | ||
console.log(err.error); | ||
.catch(err => { | ||
console.error(err.error); | ||
}) | ||
// using async/await | ||
try { | ||
const data = await twitter.getCounts('iAmAlphaZz') | ||
} catch (e) { | ||
throw e | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13025
216