Closed LeonardoDavid closed 8 years ago
Hi @LeonardoDavid I am glad you like it. Be careful how you use it or you get shut down by Twitter instantly.
geocode
parameter like for lang
.Hope that helps.
Hi, analog-nico Thanks for your replay i have few more doubts
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1156:14)
at listen (net.js:1182:10)
at net.js:1280:9
at dns.js:85:18
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
2.How to deploy this bot to google cloud
Regarding 1 just remove this code and then you can run multiple bots locally.
Regarding 2 you have to find out yourself I am afraid of.
Hi, Thanks for the answers, to prevent the Bot from reaching twitter api rate limits, i think we can add muliple api keys and rotate the Api keys every 15 minutes the bot runs is it Possible if yes, can you tell me how
Please read the Don't spam! section of the README. It links important sources that allow you to decide if you are heading in the right direction.
As far as I can tell you are underestimating Twitter's spam detection mechanisms and want to push the amount of replies too far. For that I can no longer be your accomplice. I am sorry.
i am not trying to spam anyway thank you for your time
It is good to hear that you have good intentions. Happy coding!
i am learning to code for about an year i am beginner in Python and JavaScript, could suggest me any tutorial for the last question i asked you
Mmh, good question. I learned a lot from the free material of https://teamtreehouse.com back in the day. If you sign on for a free trial you may find good courses about node.js. Or ask Reddit.
Hey buddy, if you promise me you don't spam then you may find the answer to key rotation in this issue: https://github.com/analog-nico/twitter-reply-bot/issues/2
Hi, Thank you
i wanted to Post Tweets Without Images, like you said i removed Media Upload code in replay.js but i am getting a error when i am running this here is the Error Message
Unhandled rejection TypeError: Cannot read property 'text' of undefined
at compileTweet (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\lib\responses.js:10:38)
at Object.module.exports.getNextTweet (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\lib\responses.js:30:16)
at C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\server.js:66:43
at tryCatcher (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\util.js:26:23)
at Promise._settlePromiseFromHandler (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\promise.js:507:31)
at Promise._settlePromiseAt (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\promise.js:581:18)
at Async._drainQueue (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\async.js:128:12)
at Async._drainQueues (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\LEONARDO\Desktop\bot\nodejs\Tester\node_modules\request-promise\node_modules\bluebird\js\main\async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:367:17)
Here is my reply.js code
'use strict';
var BPromise = require('bluebird');
var Twitter = require('twitter');
var client = new Twitter(require('../settings.json').twitter_api);
module.exports = function (compiledTweet) {
return new BPromise(function (resolve, reject) {
var data = require('fs').readFileSync(compiledTweet.image);
if (err) {
reject(err);
return;
}
console.dir(media);
if (!media || !media.media_id_string) {
reject(new Error('Image upload failed.'));
return;
}
var status = {
in_reply_to_status_id: compiledTweet.replyTo,
status: compiledTweet.text,
media_ids: media.media_id_string
};
client.post('statuses/update', status, function (err, tweet, response){
if (err) {
reject(err);
} else {
console.dir(tweet);
resolve(tweet);
}
});
});
};
"Cannot read property 'text' of undefined" means that you access the property .text
of a variable that is undefined
. If you search your code for "text" you find "compiledTweet.text". That means compiledTweet
is undefined
.
hi, can you give me link to the Twitter API Library you used
Hi, to import random twitter API Keys i replaced credential code in request.js
var twitter_api= require('../settings.json').twitter_api;
var credentials = twitter_api[Math.floor(Math.random()*twitter_api.length)];
But i am getting this error Unhandled rejection Error: [object Object]
You may use process.on('unhandledRejection', ...)
to catch the rejection and look into its cause.
Hey, Thanks for Helping, Sorry, i did not posted full error messages last time These are the errors i am getting
Unhandled rejection Error: [object Object]
at Object.ensureErrorObject (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\util.js:261:20)
at Promise._rejectCallback (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\promise.js:469:22)
at Promise._settlePromiseFromHandler (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\promise.js:513:17)
at Promise._settlePromiseAt (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\promise.js:581:18)
at Async._drainQueue (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\async.js:128:12)
at Async._drainQueues (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\LEONARDO\Desktop\TwitterApp\node_modules\request-promise\node_modules\bluebird\js\main\async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:367:17)
i searched google found solution for few but i dont know which code i need to change
Granted, the stack trace doesn't help. The issue is that somewhere in the context of a Promise
an Error
is thrown. The Promise
, however, has no .catch(...)
handler. Thus an "unhandled rejection" is produced.
If you can solve this you definitely improved your JavaScript skills by a big step!
can you tell me which code and which line i need to fix
Take that as a challenge to improve your skills. You can do it!
Best way to approach this is to get a debugger running. Webstorm contains a very user friendly one.
HI, i have been trying for 2 days i still cant figure out whats wrong. i think my code for importing random keys might be wrong
is the code is right or wrong
'use strict';
var request = require('request-promise');
var _ = require('lodash');
//var credentials = require('../settings.json').twitter_api;
var twitter_api= require('../settings.json').twitter_api;
var credentials = twitter_api[Math.floor(Math.random()*twitter_api.length)];
function getRequestOptions(options, includeUserToken) {
_.assign(options, {
oauth: {
consumer_key: credentials.consumer_key,
consumer_secret: credentials.consumer_secret
},
headers: {
'Accept': '*/*',
'Connection': 'close',
'User-Agent': 'node.js'
},
json: true
});
if (includeUserToken) {
_.assign(options.oauth, {
token: credentials.access_token_key,
token_secret: credentials.access_token_secret
});
}
return options;
}
module.exports = function (options, includeUserToken) {
options = getRequestOptions(options, includeUserToken);
return request(options);
};
Since your random key importing works well - I tested it - the error is produced somewhere else.
Whatever your error is it should have been caught here. I get the impression you somehow changed the code in other parts that at least screwed the promise chains up so that the error doesn't get caught properly but instead results in an Unhandled rejection
.
To get more insights into your error add these lines to server.js
right below the require
statements:
BPromise.onPossiblyUnhandledRejection(function (err) {
console.dir(err);
});
Instead of "Error: [object Object]"
you should see now the contents of the object. Or even better, use your debugger, put a breakpoint on the console.dir
line, and take a closer look at err
when the execution stops there.
Use your debugger to step through everything and with that zero in on the cause! If you want to improve your debugging skill in general this book is a real gem: https://www.amazon.com/Debugging-David-J-Agans-ebook/dp/B002H5GSZ2 It is one of a handful books which really stand out from all the books I read in my life!
Hi, This Bot is very useful for me i have few question about this bot