bluebirdie
v0.2.3
Published
A lightweight wrapper for the Twitter API
Downloads
2
Maintainers
Readme
BlueBirdie is very new and still in it's experimental phase. Especially with the streaming. Until the 1.0 release, this library is highly likely to change. All parts of BlueBirdie are under construction.
$ yarn add bluebirdie
const twitter = new BlueBirdie({
apiKey: 'api_key',
apiSecretKey: 'api_secret_key',
bearerToken: 'bearer_token',
});
twitter.app
.get('/1.1/statuses/lookup.json', {
params: {
id: ['1278747501642657792', '1255542774432063488'],
},
})
.then(data => console.log({ resultOne: data }));
twitter.app
.get('/2/tweets', {
params: {
ids: ['1278747501642657792', '1255542774432063488'], // Edit Tweet IDs to look up
'tweet.fields': ['lang', 'author_id'], // Edit optional query parameters here
'user.fields': 'created_at', // Edit optional query parameters here
},
})
.then(data => console.log({ resultTwo: data }));
const twitter = new BlueBirdie({
apiKey: 'api_key',
apiSecretKey: 'api_secret_key',,
accessToken: 'access_token',
accessTokenSecret: 'access_token_secret'
})
twitter.user.postForm("/1.1/statuses/update.json", { status: 'testing 12345' })
.then(results => {
console.log("results", results);
})
.catch(err => console.log({ err }))
twitter.user.post('/1.1/direct_messages/events/new.json',
{
event: {
type: 'message_create',
message_create: {
target: { recipient_id: '123456' },
message_data: { text: 'Hello World!' }
}
}
})
.then(results => {
console.log('results', results);
})
.catch(err => console.log({ err }))
twitter.user.get('/1.1/statuses/lookup.json', {
params: {
id: ["1278747501642657792", "1255542774432063488"],
}
}).then(data => console.log({ resultOne: data }));
twitter.user.get('/2/tweets', {
params: {
"ids": ["1278747501642657792", "1255542774432063488"], // Edit Tweet IDs to look up
"tweet.fields": ["lang", "author_id"], // Edit optional query parameters here
"user.fields": "created_at" // Edit optional query parameters here
}
}).then(data => console.log({ resultTwo: data }));
Twitters API v2 supports streaming for Applications and User Contexts. The version 1 API only allows streaming from the User Context.
const rules = [
{
value: 'dog has:images -is:retweet',
tag: 'dog pictures',
},
{
value: 'cat has:images -grumpy',
tag: 'cat pictures',
},
];
await twitter.app.post('/2/tweets/search/stream/rules', { add: rules });
// This can be twitter.user or twitter.app
const stream = await twitter.app.getStream('/2/tweets/search/stream');
stream
.on('data', data => {
console.log({ yay: data });
})
.on('error', err => {
console.log(err);
});
// Currently, there is a manual baseURL override, since version 1 api is on a different domain. If the bluebird client instance is only going to be used for version 1 stream, the domain can be set in the config.
await stream = twitter.user.postStream(
'/1.1/statuses/filter.json',
{ track: 'jojo' },
{ baseURL: 'https://stream.twitter.com' }
);
stream
.on('data', data => {
console.log({ yay: data });
})
.on('error', err => {
console.log(err);
});