15.5: Scheduling Tweets Using setInterval() - Twitter Bot Tutorial
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- How do you schedule tweets in a bot using JavaScript's setInterval() function? How do you trigger a tweet when a certain event occurs like a user is followed or a tweet is favorited?
All examples: github.com/shi...
Twit package: github.com/tte...
Twitter API documentation: dev.
Twitter automation rules and best practices: support.twitte...
Contact: / shiffman
Next video:
• 15.6: Tweeting images ...
Learn JavaScript basics:
• Start learning here!
Learn Processing basics:
www.youtube.co...
More about data and APIs:
• 10: Working with data ...
Help us caption & translate this video!
amara.org/v/Qbtn/
📄 Code of Conduct: github.com/Cod...
Wow I cant believe someone literally enjoys teaching like that!
Its 4 AM and Im stuck in thease videos.
If you're using this now the twitter removed the user endpoint so T.stream("user") doesn't work use var stream = T.stream('statuses/filter', { track: '@' }); instead.
Does the "your_twitter_username" Refers to the bot username?
@@saitejaballa6759 yes
thsis deosn't work either. do i have to change something else aswell?
Hey Daniel! Just came across this video series and has helped me setup and run a local node server to pull the current spot rate from my power company API so I can use it to calculate the cost of power via an IoT device power meter I created... speaking of which I would love to see a series on Arduino! Cheers for making me smarter... 4 days ago I had never written a word of JS! From New Zealand! Chur bro
I'll Shoot You nice work man! What's the device you set up? I'm interested.
After watching this, I made a Motivation Quote Bot, which will tweet a motivation quote every 24 hours.
Thank you so much!
As always very well explained! The bit I found most useful was when you opened up the twitter page and put everything into context - cheers for that!
Thank you for the nice feedback!
You are amazing, i love your explanations they feel so warm or i don't know how to say it but it feels like i'm in a conversation in which i'm learning
I have implemented this idea: a small joke bot in twitter that posts a joke every 1 hour.
How did you do that, did you manually inserted each joke in a variable and passed it inside the post() or something else. I need the answer ?
Shivam parashar use an array of string jokes and increment its index for each post, or look for a random jokes API and connect it to your bot so you can get new jokes each time your bot's posts.
@@shivamparashar641 you can use an api which can generate random jokes for you
github.com/bluekandil/Javascript_twitterBot/blob/master/bot.js
That moment when you need to try the follow event but you got no friends :'( Haha great video again =)
+Furrane thank you!
For indent, you can go to Preferences -> Settings. And then you make another property like that: "tab_size": 2
or even View>Indentation>Tab Width: 2
If you are watching this now, the Stream() function is now obsolete and will not work. Instead, use the Account Activity API, it's a premium service but you can use it for free to test in the Sandbox. Find more info for in the twitter documentation by searching Account Activity API.
Thanks for the tip!
how do we use the account activity API
Truly amazing video, you are really entertaining and clear in your explanation :)
I am planning to learn AWS Lambda! Thanks for teaching the most wonderful node.js class.
I believe the stream portion is no longer applicable in 2019 as certain things have been deprecated.
the exact problem I ran into and only found out certain things were discontinued on the API
Hello Daniel,
in follow event, I see that; if I-me-myself follow a user, my bot works again. For example; my screen name in twitter is @BarbarosYrttgl. If I follow someone, tweetIt( ) function works and it says '.@BarbarosYrttgl thanks for following'. So, for the solution I recommend;
function followed(eventMsg) {
var name = eventMsg.source.name
var screen_name = eventMsg.source.screen_name
//id_str is your twitter account id
if (eventMsg.source.id_str !== 'your_twitter_account_id_here') {
tweetIt('.@' + screen_name + ' thanks for following')
}
}
Great tutorial:)Thanks.
use command+k instead of clear to clear the terminal Dan! try it.
Thank you!
Thanks
Control+L on win running bash
Your videos are really great. Thank you so much for making them!
I made a Tweeting Cat's bowl with an Arduino. it posted when the cat's bowl became close to empty, and alerted my nephews to feed the cat. Interesting to see tweeting from NodeJS, but very similar restrictions (frequency, message similarity etc)
did you use arduino as a server? do you keep it running all day? If so, how do you handle the security, firewalls etc?
@@blasttrash I would assume that the arduino is the hardware trigger that sends a message to the api to post a picture of the triggered snapshot made by the arduino
Hey Dan, thanks for the videos. Just wondering if there is a way to make a bot DM someone when they follow an account?
Thanks,
Alexis
Thank you so much for the video series!
Thank you for this series.
Hi, thank you for this great video. I have implemented the lesson in this video but every time I try running it, it returns error: Bad twitter streaming request: 404. Any Idea of what I'm doing wrong?
Heres what I found on this, github.com/ttezel/twit/issues/500 but I don't know a work around for it yet.
You are the best of the best
Thank you very much for the help you have given me
Great tutorial. Helped me a lot. :)
Can we make the bot happen through Html? Say I have a text box and a button to post. If yes, can you make a demo and add it here via link. Thanks.
This is real use of TH-cam
Have you done any updates to this playlist to discuss the changes to Twitter since these videos were made? (things that have been deprecated etc.)
I made a bot that enters contests for me 24/7. Still trying to get past some of the twitter limits, but it seems to be working well.
thank you so much ! you are just perfect !
Thanks! Implementing our bot :)
yay!
I don't find the code in your GitHub. Did you update the repository? Can you please provide the correct link? Sorry I know it's old video but I think your video still worthwhile to watch and learn.
Hey, how do I keep my twitter bot running forever, even when my terminal is closed. Thanks so much for all your help.
google "nohup". I cover this in a later video in the playlist I think?
download pm2 module
# npm install -g pm2
# pm2 startup systemd
# systemctl status pm2
go to your app folder
# pm2 start yourmainApp.js
Great question Nishka! Thank you shiffman and Koko Master for sharing!
Pm2
This is extremely helpful, @The Coding Train. Thank you! Wondering how you are getting the green screen situation?
great series!
Holy shit watching this September 16 2019 and there are 0 dislikes on this vid. Legendary
You had to say it didn't you?
@@damiamquimtana573 I mentioned the date because I knew some dick head would dislike it eventually. Still, 4 years with no dislikes and 60K views is impressive
@@dsadad21 I remember one video of kirby that endure like 5 years without a dislike
@@damiamquimtana573 foreal, send me the link
@@dsadad21 th-cam.com/video/RzM_-YTnQo0/w-d-xo.html
apparently it was more than 5 years cuz it was from the 2009
Hey Dan! Do you know any sort of way I can use the icanhazdadjoke.com api to create a random joke and post that as a tweet? If you do it would be really helpful and also by the way I'm the first student in my school to make a twitter bot in the 9th grade. All thanks to you !!!
Looks like the API used via var stream = T.stream('user'); refers to a now deprecated user streams endpoint (removed 7 days after starting my bot build!) Any thoughts on a way round this?
I need to look into this!
its not working provide a solution bro
I found this, but looking through the links provided it's a bit over my head. If anyone can help figuring it would be appreciated! stackoverflow.com/questions/51905999/node-js-twitter-bot-returning-error-bad-twitter-streaming-request-410/51931966
@@TheCodingTrain This project is so cool!! Please help us if there is a there a work-around to this issue!
@@TheCodingTrain whats the solution!
So my first take a youtube live chat event and repeats one of them to Elon's twitter. already hit my 50 tweet limit today again lol these npm's are a blast xD
Hola, estoy siguiendo este tutorial, pero cuando lo ejecuto, veo este error y busqué soluciones, pero no puedo encontrarlo. Te agradecería si pudieras ayudarme. Muchas gracias por el excelente video.
events.js:183
lanzar er // Evento de 'error' no manejado
^
Error: Solicitud incorrecta de transmisión de Twitter: 404
just a simple question. i cant understand the purpose of the paramater 'eventMsg' where it coming from and its purpose
eventMsg is JSON data that was pulled from the stream.on followed event. It can be named anything.
Think of it similar to a click event (eventListeners) and you want to pull where the User clicked on... (ie. event.target)
As of 2018, I get this error for the follow message stream function.
hmmm...
The follow bot is starting...
events.js:183
throw er; // Unhandled 'error' event
^
Error: Bad Twitter streaming request: 410
I'm also having the same problem, it's because twitter doesn't allow for the stream APIs anymore, you need to use account activity API which Twit package doesn't cover at the moment.
@@chanellesesh4977 ohhh I see. thanks!
thank you so much! you are awsm teacher! do you feel OK, if I take this as a sample and make my own TwitterAPI and upload it to github? thanks!
Hi want to get the status(the message to tweet) from a textbox in an html file. How do i go about it.Kindly help
thank you daniel for nice tutorial,
how to replace math random with random hashtags readit from a file txt or json?
Important: user endpoint is removed what to do now???
If I create an animation that is based on if somebody twits, for example make a ball bounce everytime there is mention of the hashtag 'basketball', i should use stream(), correct? Thanks for these awesome lessons!
Can you please sand me the code from this example? Would be very interesting to me.
does the follow works only when someone follows me or it triggers the callback even if i follow someone else?
Is there a similar one for whatsapp?!
Thank you for the knowledge
How to send message directly to the particular user
Hi Daniel!! If i want to post every hour, i have to keep my computer turned on until i want the bot to stop? Is there a way to keep the bot alive without having to keep my computer on? Thanks!!
I cover this in a later video. th-cam.com/video/26bajyD4fLg/w-d-xo.html You can also check out my video on web application deployment th-cam.com/video/Rz886HkV1j4/w-d-xo.html
hi, @The Coding Train Notice - can we make a bot that will do video editing itself, like we give it parameters like videos and tell it to cut them and combine them and add filters and transition to it. We often do the same things while video editing and can we make a bot to do these same tasks again and again. Thanks
Daniel, great videos for beginners!
I hope you also can offer some help for further questions. I'm looking for the twitter command to identify, if my bot has already retweeted a specific tweet. In Twitter developers I have found current_user_retweet. But I have no idea how to use it. Do you?
I would keep track of a list of tweet IDs yourself and then compare from your code.
ur awesome ....this is so cool
Hi Daniel,
I was hoping you could perhaps help me with setInterval and stream.on. would like to set an interval to connect to a stream, call a function and then quit the stream and repeat after given time specified.
Is this possible, and what would the code look like for example?
I tried to change the Follow example to an unfollow event by just changing 'follow' to 'unfollow' in the stream line and it didn´t worked. Can't figure why if it's on the Twit stream events documentation.
+latostadorano Strange, it should work I think too! I also see it in the twitter docs. dev.twitter.com/streaming/overview/messages-types I'll have to look into this at some point. Let me know if you discover anything.
so I'm having a strange error setInterval while following this video. I'm trying to pass a parameter into the tweetIt function, which is contained within a setInterval and it keeps bombing out on the second interval. It took me awhile to narrow it down, but i have these two code samples:
This works:
setInterval(log,1000);
function log() {
console.log("log");
}
this does not:
setInterval(log("test"),1000);
function log(txt) {
console.log(txt);
}
The big picture idea is to call a function like this:
setInterval(tweetIt(generateTweet),5000);
the generateTweet function generates a string based on the time of day, weather, whatever.
tweetIt then tweets the string, but it only works once before bombing out with this error
C:\Dropbox\webDev\www
ode>node notworking
test
timers.js:275
timer._repeat();
^
TypeError: timer._repeat is not a function
at wrapper [as _onTimeout] (timers.js:275:11)
at Timer.listOnTimeout (timers.js:92:15)
C:\Dropbox\webDev\www
ode>
+Tiny Starship as usual 1 minute after posting a cry for help I figure it out. I had to change it to an anonymous function and it started working!
thanks for the whole series, watched everyone and it helped me create a fake news bot for a game I'm creating. Working on making it a little more interactive. You mentioned in video 6 or 7 about creating a video on deploying our scripts to a server. Right now I'm just running it off of my iMac at home, would love to see that video :)
Now this works:
setInterval(function(){log("test")},1000);
function log(txt) {
console.log(txt);
}
you are awesome !!
it's also note worthy if you want to tweet Elon 50 times on more free access, remember you only get 50 tweets in 24hrs oops xD Lol it was for happy to use a "for loop",lol was less then a few second xD
are you going to remake this video since the User stream was closed on twitter?
Wow, TH-cam may be where the real fun is to be had now xD it's so happy to just cough up 100s of comments and everything else, it seams very verse in google letting you do anything so far you ever wanted from twitter like wordnik xD not complaining about twitter, 50tweets every 24 is still nice but i'd still like the search back like youtube has for anything and everything xD using "youtube-sdk" for node in npm
1:32 2 space indentation vs 4 space indentation
is that a thing?
If you wanted the bot to retrieve information off of a separate URL, how would you go about doing that? Would you need to insert the URL where you're getting data from?
Late response but uf someone else sees this, you need to use the npm package called "request" which can make requests to urls and get the response as a raw string.
Look into the Fetch API supported by all the main browsers.
But this is a tutorial using nodejs
hey dan nice tuto ,im working with node.js , and i have a question, i work in goddady hosting how can i charge my app on a server , and how can i install the twit api there?
I'm not sure if godaddy has servers that can run node but this is a requirements. I use Amazon ("AWS") and Digital Ocean to run my bots with node.js.
how do i display them on a webpage in a twitter styled way
Hi, I tried to listen for 'unfollow' event but my callback never got called. According to Twit API I dont have to anything extra. Any idea what could be the issue? Thanks
Just found that unfollow this will only be sent when the authenticating user unfollows someone, not when someone unfollows the authenticating user.
I wonder if those api secrets / keys are still active ?
that was fun
Sorry, I know I'm really late posting this, but after I add the "tweetIt ();" and the "function tweetIt() {" and try to run the bot, it says "SyntaxError: Unexpected token )"
Could you help me? thanks.
Hard to debug here, maybe try posting on a forum (stack overflow?) and link from here.
Im trying to get through this series but i have an overwhelming urge to take your lunch money.
Can you just take it down a notch in the future? Ty
How could I get this bot to work without having my laptop running? What is the technology required for it?
keep watching!
you would have to host it somewhere like on heroku. i think he shows you how to do that later on.
Can I get full code? Wanna test
can you please tell, how to retweet or fav. users tweet when they tweet with some specific hashtag!
+Parvesh Narwal you'll have to poke around the twitter API. maybe I can add some examples. Favoriting, for example, is here:
dev.twitter.com/rest/reference/post/favorites/create
+Daniel Shiffman Thanks. This is helpful.
I love you
TypeError: Cannot read property 'source' of undefined.. someone please help
you probably missed something from the renaming at 10:20
Hi! :) Is it possible to make a bot who reply when someone follow and tweeting images with Processing? Thanks!
Yes indeed, the pieces of this are in my examples on github!
+Daniel Shiffman I don't see it :( I see files to make that but separately, is there a file who combine both?
Hey Shiffman, I'm running code for 'follow' event and my cmd prompting
Events.js:183
Throws er; // unhandled 'error' event
Error: Bad Twitter streaming request: 410
Please let me know how to fix this
Thanks for your time
Twitter deprecated the streaming API sadly. You can check out my new Mastodon bot tutorials if you like!
Yes I was also pulling out my hair since an hour, why it is not working and then found that it is deprecated,huuuh It sucks man☹️
T.stream('user') is possible to abolish these days.
What should I try instead? I'm trying it but it seems no working
Hey!! You're amazing but it doesn't work if a private twitter account follows me!
how i run it code on windows? pls help
please don't ever try to use it on facebook,
i've used it but all went wrong
your stories will be published but can't be seen by your followers
how do I reply to a tweet?
I fucking love you
plz how to get a tweet by id and thanks :)
If you goto the Twit package site you can see it ;)
1:07 xDDD
I am shocked
1k likes n just 1 dislike 🎉🎉❤️
could I track another account beyond mine?
did you find an answer to that?
Late to the party but why not. I have code that creates an array of possible tweets, "tweetArray" that randomly selects a tweet from said array each time the function to tweet is called
var selectedTweet = tweetArray[Math.floor(Math.random()*(tweetArray.length)-1)];
This claims to successfully tweet, but doesn't seem to actually post anything, and sometimes will throw the error "Missing required parameter: status."
any advice?
Wow
yeah not working anymore
can anyone share the code?
Don't use sublime. To code use Brackets [code the web]
I don't find the code in your GitHub. Did you update the repository? Can you please provide the correct link? Sorry I know it's old video but I think your video still worthwhile to watch and learn.