Closed ssithuxz closed 7 years ago
@sithulol Hi, are you still having this problem?
Hi
I'm getting the same error. Help!
@Salloreon Hi, please make sure your account didn't get suspended, Twitter has been getting more serious about automated accounts lately and a lot of people reported having trouble getting their bots set up.
If you're still having a problem -- and you are sure your bot doesn't go against Twitter's Terms Of Service, please stop by botmakers.org and ask for more help there.
Thank you!
I'm getting the same error, when i try to launch with "node server.js" or any other js even though i have a brand new account & developper account, this has nothing to do with ToS
`random-image-twitterbot/node_modules/twit/lib/twitter.js:511 throw new Error(err_msg) ^
Error: Twit config must include consumer_key
when using user auth.
at /home/web/admin/library/random-image-twitterbot/node_modules/twit/lib/twitter.js:511:13
at Array.forEach (native)
at Twitter._validateConfigOrThrow (/home/web/admin/library/random-image-twitterbot/node_modules/twit/lib/twitter.js:508:17)
at new Twitter (/home/web/admin/library/random-image-twitterbot/node_modules/twit/lib/twitter.js:58:8)
at Object.
The error seems like i'v not even put the oauth key in the config but i did ! if you could help me would be cool :) Thanks !
Yes, sorry, it should be:
var T = new Twit(config.twitter);
Thanks, it works !
Yes, sorry, it should be:
var T = new Twit(config.twitter);
I have tried inserting this but it results in:
ReferenceError: Twit is not defined
What should I do?
I'm working on a version of your bot that tweets Windows wallpapers, and to my luck I keep having to deal with various errors.
@Glosswired Make sure to install dependencies with npm install
and load the Twit library with let Twit = require('twit')
.
If you're still having an issue, can you share your full code?
Yes, I have already installed the dependencies. The previous error was a result of me foolishly replacing throw new Error(err_msg)
in the Twit module's twitter.js file with the code you posted above, then I realized var T = new Twit(config.twitter);
is in server.js already, so I fixed it back to what it originally was.
Anyways. The error I get now is:
Error: Twit config must include `consumer_key` when using user auth.
I have filled out all of the keys in config.js, by the way.
Can you console.log
your config object? If it has the following structure:
config.twitter = {
consumer_key: 'CONSUMERKEY',
consumer_secret: 'CONSUMERSECRET',
access_token: 'ACCESSTOKEN',
access_token_secret: 'ACCESSTOKENSECRET'
}
Then you need to load it with var T = new Twit(config.twitter);
.
If it looks like this:
config= {
consumer_key: 'CONSUMERKEY',
consumer_secret: 'CONSUMERSECRET',
access_token: 'ACCESSTOKEN',
access_token_secret: 'ACCESSTOKENSECRET'
}
Then you should use var T = new Twit(config);
.
Changed the config object to config=
and it's working better... but still not actually working. For testing purposes I currently have the uploads set to every 10 secs. Each time it tries to upload something it does:
Opening an image...
Uploading an image...
ERROR:
Error: Invalid or expired token.
at Object.exports.makeTwitError (F:\Windows Wallpaper Bot\random-image-twitterbot\node_modules\twit\lib\helpers.js:74:13)
at onRequestComplete (F:\Windows Wallpaper Bot\random-image-twitterbot\node_modules\twit\lib\twitter.js:344:25)
at Request.<anonymous> (F:\Windows Wallpaper Bot\random-image-twitterbot\node_modules\twit\lib\twitter.js:364:7)
at Request.emit (events.js:215:7)
at Gunzip.<anonymous> (F:\Windows Wallpaper Bot\random-image-twitterbot\node_modules\request\request.js:1083:12)
at Object.onceWrapper (events.js:299:28)
at Gunzip.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1199:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
message: 'Invalid or expired token.',
code: 89,
allErrors: [ { code: 89, message: 'Invalid or expired token.' } ],
twitterReply: { errors: [ [Object] ] },
statusCode: 401
I don't get why it's calling the token invalid or expired, despite the fact I used the exact same one on my Twitter app. I even tried regenerating it and it persists.
Is it possible that your app was suspended?
https://stackoverflow.com/questions/17636701/twitter-api-reasons-for-invalid-or-expired-token
It hasn't been suspended. I have tried reading this page and can't identify my issue.
Would you be able to share your code?
server.js, which is pretty much just the same as yours but there might be a few differences:
var fs = require('fs'),
path = require('path'),
Twit = require('twit'),
config = require(path.join(__dirname, 'config.js')),
images = require(path.join(__dirname, 'images.js'));
var T = new Twit(config);
function random_from_array(images){
return images[Math.floor(Math.random() * images.length)];
}
function upload_random_image(images){
console.log('Opening an image...');
var random_image = random_from_array(images),
image_path = path.join(__dirname, '/images/' + random_image.file ),
b64content = fs.readFileSync(image_path, { encoding: 'base64' });
console.log('Uploading an image...');
T.post('media/upload', { media_data: b64content }, function (err, data, response) {
if (err){
console.log('ERROR:');
console.log(err);
}
else{
console.log('Image uploaded!');
console.log('Now tweeting it...');
var tweet_text = random_image.source;
T.post('statuses/update', {
status: tweet_text,
media_ids: new Array(data.media_id_string)
},
function(err, data, response) {
if (err){
console.log('ERROR:');
console.log(err);
}
else{
console.log('Posted an image!');
}
}
);
}
});
}
/*
You have two options here. Either you will keep your bot running, and upload images using setInterval (see below; 10000 means '10 milliseconds', or 10 seconds), --
*/
setInterval(function(){
upload_random_image(images);
}, 10000);
/*
Or you could use cron (code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800), in which case you just need:
*/
// upload_random_image(images);
config.js (censored out the keys and tokens):
var config = {
consumer_key: "[REDACTED]",
consumer_secret: "[REDACTED]",
access_token: "[REDACTED]",
access_token_secret: "[REDACTED]"
}
module.exports = config;
The issue seems to be with your API keys or your app, the code is working for me.
node server.js
Opening an image...
Uploading an image...
Image uploaded!
Now tweeting it...
Posted an image!
Make sure the values match, for example, that you're not passing your secret as your key, etc.
You might want to reach out to Twitter tech support and see if there are any issues with your app.
Yeah, the values match.
Unfortunately their support page only lets you report things like account, user or copyright issues and I can't see anything about apps, so I guess I should just go to the forums.
Sorry, try this one: https://help.twitter.com/forms/platform.
And yes, other than that, there's also https://twittercommunity.com.
Good luck!
Yeah, the values match.
Unfortunately their support page only lets you report things like account, user or copyright issues and I can't see anything about apps, so I guess I should just go to the forums.
Did you ever find a fix for this?
Error: Twit config must include
consumer_key
when using user auth.i am getting this error even though i have correctly put all my 4 keys in config.js
help