
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
node-twitter
Advanced tools
node-twitter is a node.js module for interacting with the Twitter API.
The Twitter REST API can be accessed using Twitter.RestClient. The following code example shows how to retrieve tweets from the authenticated user's timeline.
var Twitter = require('node-twitter');
var twitterRestClient = new Twitter.RestClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
twitterRestClient.statusesHomeTimeline({}, function(error, result) {
if (error)
{
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
}
if (result)
{
console.log(result);
}
});
The Twitter Search API can be accessed using Twitter.SearchClient. The following code example shows how to search for tweets containing the keyword "node.js".
var Twitter = require('node-twitter');
var twitterSearchClient = new Twitter.SearchClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
twitterSearchClient.search({'q': 'node.js'}, function(error, result) {
if (error)
{
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
}
if (result)
{
console.log(result);
}
});
The Twitter Streaming API can be accessed using Twitter.StreamClient. The following code example shows how to catch all tweets containing the keywords "baseball", "basketball", "football" or "hockey".
var Twitter = require('node-twitter');
var twitterStreamClient = new Twitter.StreamClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
twitterStreamClient.on('close', function() {
console.log('Connection closed.');
});
twitterStreamClient.on('end', function() {
console.log('End of Line.');
});
twitterStreamClient.on('error', function(error) {
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
});
twitterStreamClient.on('tweet', function(tweet) {
console.log(tweet);
});
twitterStreamClient.start(['baseball', 'basketball', 'football', 'hockey']);
Tweets with attached image media (JPG, PNG or GIF) can be posted using the upload API endpoint.
var Twitter = require('node-twitter');
var twitterRestClient = new Twitter.RestClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
twitterRestClient.statusesUpdateWithMedia(
{
'status': 'Posting a tweet w/ attached media.',
'media[]': '/some/absolute/file/path.jpg'
},
function(error, result) {
if (error)
{
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
}
if (result)
{
console.log(result);
}
};
);
node-twitter is made available under terms of the BSD 3-Clause License.
To run the unit tests, open tests/UnitTestMain.js in a text editor and replace the OAuth placeholder values with your OAuth credentials.
Save the file then, from the command line, run:
make test
Before submitting pull requests, please ensure your code is documented and there are unit tests for any new functionality.
FAQs
A node.js module for interacting with the Twitter API.
The npm package node-twitter receives a total of 5 weekly downloads. As such, node-twitter popularity was classified as not popular.
We found that node-twitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.