Bot that change twitter profile picture - javascript

Hey there I'd like to code a bot with nodejs to change a profile picture
var Twitter = require('twitter');
var data = require('fs').readFileSync('image1.png');
var client = new Twitter({
consumer_key: 'asd',
consumer_secret: 'asd',
access_token: 'asd',
access_token_secret: 'asd'
});'account/update_profile_image', {image: data}, function(error, tweet, response) {
console.log("done"); // Raw response object.
well it seems to work but my profile picture does not change


flickr node.js api upload photo

I build app in Node.js with Flickr API(in npm - flickrapi).
When uploaded photo, in console I get: 'photos uploaded []'.
Why empty array?
Any way after my "uploading" no photo in flickr repository.
Photo path - 'D:\test.jpg'.
Photo exist - 100%.
flickerOption - 100% correct.
var Flickr = require("flickrapi"),
flickrOptions = {
api_key: "secret_num",
secret: "secret_num",
user_id: "secret_num",
access_token: "secret_num",
access_token_secret: "secret_num"
Flickr.authenticate(flickrOptions, function (error, flickr) {
var uploadOptions = {
photos: [{
title: "test",
tags: [
"happy fox",
"test 1"
photo: "/test.jpg"
}, {
title: "test2",
tags: "happy fox image \"test 2\" separate tags",
photo: "/test.jpg"
Flickr.upload(uploadOptions, flickrOptions, function (err, result) {
if (err) {
return console.error(error);
console.log("photos uploaded", result);
flickerOption was right on 99%. I forgot to register permits.
The right way:
var Flickr = require("flickrapi"),
flickrOptions = {
api_key: "secret_num",
secret: "secret_num",
user_id: "secret_num",
access_token: "secret_num",
access_token_secret: "secret_num"
permissions: 'delete'
flickrapi documentation:
permissions: "delete" will give it read, write and delete access

Authentication error when using request npm

var request = require('request');
url: ',users,search,statuses',
oauth: {
consumer_key: 'Keys'
, consumer_secret: 'are'
, access_token: 'here'
, access_token_secret: ''
}, function (error, response, body) {
if (error) {
var json = JSON.parse(body);console.log(body);
I am getting "must be authenticated" error even though I have my keys in place and I'm not behind any proxy.Any ideas why?

Mongoose 1:Many Parent Relation Doesn't Save (says undefined)

I am new to express/mongoose and trying to implement User-Post relationship.Aka 1:Many.
I have two models,
// *models/user.js
var mongoose = require('mongoose');
var userSchema = mongoose.Schema({
email: {type: 'string'},
password: {type: 'string'},
posts: [{type: mongoose.Schema.Types.ObjectId, ref: 'Post'}]
module.exports = mongoose.model('User', userSchema);
// *models/post.js
var mongoose = require('mongoose');
var postSchema = mongoose.Schema({
user : { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
body: String,
title: String
module.exports = mongoose.model('Post', postSchema);
Post = require('./models/post');
User = require('./models/user');'/api/posts',(req,res)=>{
User.findOne({email: "valid_email"},(err, user)=>{
var post = {
title: "Post 1 Title",
body: "Post 1 body",
user: user._id
Post.create(post, (err, post)=>{
Now, this approach is working for saving the Post which belongs to user with email "valid_email".I can reach out it's user by populating.
app.get('/post', (req,res)=>{
Post.findOne(title: "Post 1 title")
.exec(function (err, user) {
if (err) throw err;
I thought generating a Post in the callback of finding a User would automatically push it to User's posts.Not only it is not how it works, i can't push manually to "user.posts".
It says can't "push" to undefined.When i console.log(user.posts) i get undefined.
How is it that i can generate a Post belongsTo a User, then i can populate the user just by it's id, but can't push a Post to User? It gives undefined "user.posts" ?
!!! I got it working.'/api/posts', (req,res)=>{
User.findOne({id: _some_user_id}, (err,user)=>{
var poster = user;
var post = {title: req.body.title, body: req.body.body, category: req.body.category, user: poster}
Post.create(post, (err,post)=>{

Upload a video to Youtube using Node.js using a stream

I can easily update a video to Youtube:
var googleapis = require('googleapis');'youtube', 'v3').execute(function(err, client) {
var metadata = {
snippet: { title:'title', description: 'description'},
status: { privacyStatus: 'private' }
.youtube.videos.insert({ part: 'snippet,status'}, metadata)
.withMedia('video/mp4', fs.readFileSync('user.flv'))
.execute(function(err, result) {
if (err) console.log(err);
else console.log(JSON.stringify(result, null, ' '));
The problem is that for large files that fs.readFileSync is very un-practical.
Apparently this was fixed but the example provided is for Google Drive:
var fs = require('fs');
var drive ={ version: 'v2', auth: oauth2Client });
resource: {
title: 'testimage.png',
mimeType: 'image/png'
media: {
mimeType: 'image/png',
body: fs.createReadStream('awesome.png') // read streams are awesome!
}, callback);
How do I upload to Youtube using a stream?
In my case I am able to upload using this module for large file(>2GB).
var youtube = require('googleapis').youtube('v3');
'auth': auth,
'resource': resource,
'part': part,
'media': fs.createReadStream(videoFilePath)
}, callback);

npm twitter API not working?

Trying to perform a basic stream using an example. I have the code:
var twit = require('twitter');
var twitter = new twit({
consumer_key: '[KEY]',
consumer_secret: '[SECRET]',
access_token: '[TOKEN]',
access_token_secret: '[TOKEN-SECRET]'
});'statuses/filter', {track: 'food'}, function(stream) {
stream.on('data', function(tweet) {
stream.on('error', function(error) {
throw error;
Doent responds with anything.
Please notice that in official document the key name should be:
var client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '', // instead of: access_token:
access_token_secret: ''