Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-twitter-api

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-twitter-api - npm Package Compare versions

Comparing version 1.7.1 to 1.7.2

2

package.json
{
"name": "node-twitter-api",
"version": "1.7.1",
"version": "1.7.2",
"description": "Simple module for using Twitter's API in node.js",

@@ -5,0 +5,0 @@ "keywords": ["twitter", "oauth", "rest", "streaming"],

@@ -109,3 +109,8 @@ # node-twitter #

* _isBase64_: Set to true, if media contains base64 encoded data
For a example result see https://dev.twitter.com/rest/reference/post/media/upload. You can pass multiple media_ids to the statuses/update endpoint by seperating them with commas (e.g. "[id1],[id2],[id3],[id4]").
For a example result see https://dev.twitter.com/rest/reference/post/media/upload. You can pass multiple media_ids to the statuses/update endpoint by seperating them with commas (e.g. "[id1],[id2],[id3],[id4]").
## How to upload Video ##
To upload video to Twitter, call `twitter.uploadVideo(params, accessToken, accessTokenSecret, callback)` with params containing the following:
* _media_: Path to the file containing the video.
You can pass media_id to the statuses/update endpoint and video will be uploaded to twitter. Please note that video should be less than 15mb or 30 sec in length.
"use strict";
var VERSION = "1.7.1",
var VERSION = "1.7.2",
querystring = require("querystring"),

@@ -296,2 +296,86 @@ oauth = require("oauth"),

/**
* upload video to twitter
* @param params
* @param accessToken
* @param accessTokenSecret
* @param callback
*/
Twitter.prototype.uploadVideo = function (params, accessToken, accessTokenSecret, callback) {
var bufferLength = 1000000;
var theBuffer = new Buffer(bufferLength);
var offset = 0;
var segment_index = 0;
var finished = 0;
var oauthObj = {
consumer_key: this.consumerKey,
consumer_secret: this.consumerSecret,
token: accessToken,
token_secret: accessTokenSecret
};
fs.stat(params.media, function (err, stats) {
var formData, finalizeVideo, options;
formData = {
command: "INIT",
media_type: 'video/mp4',
total_bytes: stats.size
};
options = {
url: uploadBaseUrl + "media/upload.json",
oauth: oauthObj,
formData: formData
};
finalizeVideo = function (media_id) {
return function (err, response, body) {
finished++;
if (finished === segment_index) {
options.formData = {
command: 'FINALIZE',
media_id: media_id
};
request.post(options, function (err, response, body) {
if (err) {
return cb(err, body);
} else {
try {
return callback(null, JSON.parse(body));
} catch (e) {
return callback(e, body);
}
}
});
}
};
};
request.post(options, function (err, response, body) {
var media_id;
media_id = JSON.parse(body).media_id_string;
fs.open(params.media, 'r', function (err, fd) {
var bytesRead, data;
while (offset < stats.size) {
bytesRead = fs.readSync(fd, theBuffer, 0, bufferLength, null);
data = bytesRead < bufferLength ? theBuffer.slice(0, bytesRead) : theBuffer;
options.formData = {
command: "APPEND",
media_id: media_id,
segment_index: segment_index,
media_data: data.toString('base64')
};
request.post(options, finalizeVideo(media_id));
offset += bufferLength;
segment_index++
}
});
});
});
};
// Search

@@ -298,0 +382,0 @@ Twitter.prototype.search = function(params, accessToken, accessTokenSecret, callback) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc