Discover the basics of APIs, how to authenticate with an API, familiarize yourself with any social media API, and set up your own social media bot in this insightful video seminar. These skills can significantly enhance your career in data science or software development.
Key Insights
- The video seminar provides an understanding of the basics of APIs (Application Programming Interfaces).
- Participants will learn how to authenticate with an API, a crucial step in managing data flow between different software applications.
- The seminar offers training on how to familiarize oneself with any social media API, a skill valuable in today's digital marketing landscape.
- Attendees will gain knowledge on setting up their own social media bot, which can automate tasks and improve efficiency.
- These skills can be further sharpened through Python classes and bootcamps, offering hands-on training.
- Data science classes and certificate programs are also available for individuals interested in diving deeper into data management and analysis.
Want to try your hand at building a social media bot? In this free seminar, we'll lay the foundation for creating a Twitter bot. Whether you want to create a bot that sends personalized messages, posts useful hyperlinks, or keeps your followers up-to-date with your company's latest press releases, this class is a must.
In this seminar, you'll gain a foundational understanding of how to interact with Twitter and similar social media platforms via the Python programming language.
In this video seminar you’ll learn:
- Basics of APIs
- Authentication with an API
- How to familiarize yourself with any social media API
- How to set up your own social media bot
Learn More
See our Python classes & bootcamps or data science classes & certificate programs to learn more in hands-on training that can be done live ononline or in-person in New York City.
Video Transcription:
good evening everyone my name is phthalo um welcome to this uh yep free uh seminar on i'm creating a twitter bot um first off um i just wanna get some little technical things out of the way so if anyone does already have python installed you know feel free to follow along with uh jupiter notebook i'm going to go ahead and be using a google colab though so here let me just put the name of this in the zoom chat here there we go um so google colab is just a great free online resource that google offers in order to be able to run the equivalent of jupiter notebooks so these won't actually be running off of your computer they are actually running on google's computer somewhere and once you click on that link just this this first one that comes up when you type in google collab you know google collab is very uh fancy and used for all kinds of things but we're just going to be using it to make a twitter bot um and here we go uh once you do click this link it should just tell you hey do you want to create a new notebook you'll say yes i do want to create a new notebook and it might take a sec but then a screen that resembles this one should show up here i just have a very simple line of code running just to you know hit run and demo how it works and that everything's running that i am getting hello world down here with just this very simple python print statement um and um as as we'll be seeing um google cool lab does allow you to um use a whole swath of python libraries including uh tweefy or or twee pie i suppose um which is the library that we're going to be using later for actually hooking up our uh our twitter bot so first before we get into it but before we actually get to um making the bot itself um there's just a few little things um we have to know um so this is just a free seminar welcome to anyone so we're not assuming that you guys know anything about um python here for anyone just joining let me go ahead and write the name of the environment i'm using one more time it's called google colab if you do just google that it should be the first result that pops up and you can just tell it you would like to create a new notebook there should be a button that just says new notebook all right so there's a couple things we're going to have to know first what is a python list and what is a python dictionary python just spells these dict so first a python list looks something like this so it has a name i might call mine a list and it's a collection of some information in some square brackets so for example this might be a perfectly good python list i'll just go ahead and ask it to print it out and run it and here all right i have my list of python objects these are just numbers now that we're seeing what a list looks like there's just uh one thing i want to mention what we can do with the list we should know how do we access how do we access items in a list um so right now there's all five of them and if i want to see all five of them i mean that's great right i can just ask to print out the whole thing but if you just want to see one item if i want to isolate just one of these we're going to use what's called list indexing we're going to grab these based on their position so right there's five different items in that list they're at five different positions throughout that list um so it's based on their position where the first position is zero so what's that actually going to look like when i access something based on the position zero well i'll say the name of my list a list i'll put another pair of brackets here um just a pair of brackets right after the name of the list and i'll put a number in here if it's just zero all right we just see the 50. but of course you know i can make it something else zero one two here it's two now it is the seventy in that list so all right cool this is just a little bit of background that that we're going to have to know um now what is a python dictionary here maybe i'll just do this in a separate cell if you guys do want to create new cells of code you can just click this button or there's also a button right here um there we go so what is a python dictionary well much like the last one let me just show you what one might look like so here this is what a python dictionary might look like and i'm just going to ask to print it out and hit run and all right we see it's a little bit different from just a list actually i kind of want to make it display without calling print um it just displays it in a slightly different way so this is what a python dictionary looks like as opposed to having some square brackets around the edges it has some curly braces here um and as opposed to just being sort of a list of stuff here i just had some sort of i'll call this flat just had some flat stuff in the list here we have not just things based on their position we have um keys paired with values so this first key is name and its corresponding value is john smith so this this might be a dictionary describing a person it's a pretty simple dictionary there's not that much uh information about this person but we see what their name is we also see what their address is and here i i'm contrasting it with my list which was flat in that the address has inside of itself another pair of curly braces and this other pair is actually another dictionary it's actually a dictionary inside of a dictionary and inside this dictionary we have another two keys street and city and those have some more corresponding values 21 2nd street and new york so all right cool cool this is what a dictionary looks like well the same question stands the same question that we asked about this list how do we access items in a dictionary this is not going to be based on their positions so this is a just a little bit different from a list we're going to use dictionary key lookup we're going to look up values based on their key so inside this dictionary i mean you may notice just just immediately the way that it got displayed is not necessarily the way that it got keyed in right when i was creating the dictionary i first wrote the name and then i wrote the address um and and within here i wrote the city or sorry the street then the city um we're seeing you know it just so happens that the address came back to us first then the name um all of this is just showing us how the order doesn't matter dictionaries have no concept of order as opposed to a list instead they have a concept of keys and values so instead i might say hey what is the name entry in this dictionary and when i ask to run this we will see just that name just john smith i could have instead asked for the address which would have given me another dictionary right so this whole thing is the response from asking for the address and here we have more keys with their corresponding values so in here i might also add another pair of brackets and say okay within that address i just want to see the city um let's see uh someone asked will we get a recording of this webinar would like to go through this slowly at my own pace um i i know this is being recorded um i'm i'm honestly not the person to ask um but i i believe um you guys should be able to um yeah have access to the recording i'll post some information about that at the end all right thanks all right so here right i know i know we are going through this kind of fast just kind of trying to lay the groundwork in you know less time than i would usually teach this but all right here we're seeing as opposed to a list that has locations based on where they are you know things like zero one two three four um inside this dictionary i have just some entries name and address um and you know address has some more entries inside of that street and city and all right cool by instead of putting locations by putting these keys inside of here we can grab the correct value all right cool so this is just a little bit of uh background that we're gonna need um so we're building our way up to our uh twitter bot um now i wanna mention um real quick i want to say um i want to describe what an api is um and i want to describe what a json blob is maybe i should do this in the other order i think i think json is a little bit um easier to describe first so json first off yeah what is what is json so you guys may have heard this word before maybe not um it just stands for javascript object notation um which is actually a misnomer i know the word javascript is in the name but in truth these are language agnostic they they work for whatever computer programming language um it's really just a um uh format for data um it's not associated with with javascript in any particular way other than its uh original inception um but really this is a popular simple format for uh sending data around um it's popular in part because of its simplicity because it is both human readable and convenient for computers especially convenient for us us just because we're using python is that these really look identical to python dictionaries and these are a very common a very common format um four apis you guys are gonna be the next thing we talked about um so all right that means that this little thing that we saw up here this really i mean i was calling it a python dictionary but it just as well could have been a json object or also called a json blob um how they got the name blob i'm not exactly sure but all right they look just the same as a python dictionary and so here you know i know this first one we were looking at was just a very simple dictionary to get us started um but let's just see let's just see an example of a more realistic um and and somewhat complex uh json blob that might be the response we get from an api so here this one was pretty simple um i'm going to continue on with this one here i'm going to paste this one in the chat too so you guys can copy and paste it and follow along in google collab as well um whoops zoom is having me send someone a direct message there we go all right all right so you can grab that from the zoom chat you should be able to see just the same thing that i pasted here i went ahead and called this api response because this is this is resembling i mean of course mine isn't literally from an api i did not grab this from from the web or anything i just typed it out um but this really is something like what um a um an api might give us um so what are apis what are apis before i dive into this before i dive into this slightly more complex looking version of a python dictionary all apis are well here first let me let me break down the acronym um so it just stands for um application um programmable interface um and uh we we we can just read this name literally um and by that i just mean okay well there are human interfaces for um applications um so twitter for example that that's the bot that we're going to be um making in at least uh in this hour um twitter has a human interface it has actually several right it has a desktop human interface it has a a mobile human interface right and on any human interface um for or right also just called user interfaces we as humans get to sit behind a keyboard and a mouse or a phone screen and you know look at things with our eyes and click around on things and type things into fields and that type of interface makes a whole lot of sense as a human as a as a person um i i really wouldn't have it any other way um but when we're talking about making a bot um we're talking about being able to interact with twitter not just as a person but we're talking about being able to program something where that thing will interact with twitter we're going to want to be able to program a way for our bot to read tweets we're going to be able to program a way for our bot to write tweets and the way that we'll do this programmatically is not the same as the way um that we would do this if we ourselves were interacting with the website typing things in and clicking around and viewing things with our eyes um so that's that's really all uh we mean by an application programmable interface an interface that instead of being human-friendly is friendly friendly for some some software that we write some piece of code that we write um so um i'll i'll just write it this way um it's essentially a website it's not necessarily a website though often a website and for us this will be a website um a website or just other interface um specially designed for accessing um not through your mouse and keyboard um but through a program through something that we write as code so this is really all we mean by an api um and json just so happens to be a very common format for an api to give us back here i just have an example of you know i i did not literally grab this from an api but there are apis that give you responses that look a whole lot like this where perhaps i asked my program to you know fetch some information about apple and microsoft and you know whatever this website was well it was something that had some information about who their ceos were and and you know the the just spelled out company name and some tags about these companies so now that i have this response um okay how should i actually use it how should i actually pull out individual pieces of it let's just let's just think about this for a moment so if i wanted to um if i wanted to fetch the name of apple's ceo um what would i write well first in this api response i'm seeing all right it at first has two keys apple and microsoft so okay well i do one apple so here we go i haven't just zoomed in to only the name of the ceo um but okay i still have a few things in here this is another dictionary or another json blob within a json blob um i could continue sort of zooming in on just the piece that i want by writing another key here ceo and all right cool this will give me just the name of apple ceo um what we're seeing in here in in this particular one is that there's also some square brackets what look like python lists inside of here json blobs use these as well so if i wanted to see the hardware tag of apple um then what would i write so i'll give you guys a moment to think about it let's see i'm still talking about apple right the the hardware tag is here it's not under microsoft it is under apple here's that blob coming back i see hardware it's under the key called tags so let's keep going let's call this tags and now what i have is a list well can i just say can i just say hardware like this um i can't so this is not quite gonna work the reason being what i'm seeing here is a python list not a dictionary it does not have key value pairs instead i'm going to have to ask for things based on their location if i wanted technology that would be a location zero right these are always starting at location zero um and if i wanted hardware okay well that's at location one there we go so this is how i could just just get hard so here we're just sort of seeing how we can navigate through json blobs which are just a very common format for api responses to be sure um json is not the only way that apis might format their data when they're giving us some sort of response they may tell us some data in csv format in html just just html the same way that you know web pages are marked up um in xml there's there's plenty of file formats that apis might give you data in but json is just going to be a very common one and we will see the use of json in our twitter api all right so that's very convenient for us since we are dealing with python um okay okay so now um that we've got all that out of the way um i just want to show you guys what a simple api looks like we're going to actually connect to a very simple one this is not going to be um a very sophisticated one we're not dealing with the twitter api yet on the twitter api actually has quite a few rules about itself as an example we are going to be using the api for let me move this over here um a webcomic called xkcd so um this is a much simpler api than uh the one for twitter um but this is still an api there is a real api for this webcomic so here let me paste the link that i'm at right now on my screen so i'm at just at xkcd.com json.html and here they're telling us they're telling us how we can fetch some data um so this is a very small documentation page right this is the entire documentation page um later when we get to the twitter one we'll see it's uh well it's it's way more than this it's multiple pages and each one is very long um but all right as far as just any documentation page for an api um it might be just this simple i mean this is after all a real api it functions as as we'll see very shortly so in essence all apis are different the one for xkcd is certainly very different than the one for twitter but what they all have in common is that they have rules for how they're used so because they're all different we don't know in advance what the twitter api what its rules are exactly unless we read the documentation um and so here i'm just going to read through this documentation i mean all right it's just saying hey you can grab grab comics and and some metadata with the json interface cool that's what we just saw it wants us to format our urls like this so these are the rules that we as information consumers i'm going to call this information consumers because we're going to be requesting some information from this api and the the website will be serving as the information provider we are asking for some data it is giving us some data so here it's telling us okay the rules for us are to format our urls like this these are very simple rules really really not a lot you can either format your url like this to grab the current comic the most recent comic or you can format your url like this to grab a specific comic here's just their example of comic number 614 all right sure that's all the rules for us so so very simple not a lot going on what are the rules for the provider what is it supposed to give to us what can we expect to get back well here it's telling us these files contain in a plain text and easily parse format they're talking about json um comic titles urls post dates transcripts and well here they just sort of say other metadata i guess we're not exactly sure what this is um i i will say in general some api documentation is better than others um and right i mean if this were not just a web comic i would probably be pretty dissatisfied with it just saying other metadata i would probably wanted to to be a little more specific but all right as far as this one goes i'm i'm fine with that so okay cool let me go ahead and grab one of these urls i'm just going to copy this let me move this out of the way move this out of the way and i'm going to say hey this is the url that i want and i'm writing it in quotation marks writing in quotation marks just the same way that i was writing these things in quotation marks and in python we will want all of our actual text to be in quotation marks this url will be no different um oops all right so this is the url that i'm going to make my python code hit we're hitting that endpoint in order to be able to do this um so i'm not using twepee yet i'm not using the the twitter api library that we'll be using shortly um i'm just using the built-in python library for sending and receiving web requests around the internet it is just called requests um and right by request it does not mean like um i don't know the the type of request that humans might might offer to each other but i mean web requests http requests specifically so the kinds of requests that your browser sends to some server somewhere every time you go to a website so i've got my url i've imported my library um using this library it's actually very simple to hit a particular endpoint we need to send it a get request and then we need to open it up and look at the json at least for this one it's json and and we know that because we read the documentation so here i'm going to say requests.get this is going to be the syntax for and yeah co-lab google collab is showing us some documentation while we're typing it's kind of handy it is telling us okay we're supposed to put a url here well all right i created a url earlier i just put it right here i named mine url all right so i'm going to say request.get to that url it's going to give me back a response and i'm going to store that response into a variable that i'm just calling response um let's go ahead and run this so so far i sent my get request and i got a response back we haven't actually looked at it i mean here you might be saying hey we asked to print the response where where is the comic where's the the comic i thought we were going to grab and the and the metadata why does it just say this um well we haven't actually extracted the json from it yet there is one more step we need to do all i'm doing here is i'm seeing what kind of http status code this gives us i think everyone's probably familiar with 404 codes so perhaps you've gone to a website that doesn't exist and you've got a 404 code right it says uh sorry that that webpage does not exist or file not found or something like that you know i'm not going to go to in the weeds here but as far as http status codes go 200 is good that means everything's okay everything worked out fine you may also come across 300 codes which are just for redirects so um the the url that you hit ended up redirecting you to a different location um 400 codes which are uh errors on the client side that is us um right so when you hit a 404 code that is a type of 400 code the server is saying you made a mistake i'm sorry you made a mistake that that thing doesn't exist it's not my fault it is your fault that's that's what the server is really saying and you also may come across 500 codes these are an error on the server side so if you do come across 500 codes that's the server saying sorry you didn't do anything wrong my bad something went wrong on my end um and and you know i'll i'll remedy it or something you know whatever message it tells but that is an error on the server side so all right we got a 200 code and i i imagine you guys got a 200 code too but i certainly got a 200 code um so everything's good i i hit the api endpoint and i have a valid response um what do i actually do with this response well um we'll we'll end up doing this a little bit differently in uh in tweepy um but for now in the request library we're going to say requests oops and that request response the name of my response response dot json this is going to give me a json blob i'm just going to call mine blob and let's print out this blob let's see what we end up get actually when i say print it tries to do it all long like this let me let me take out print so that it tries to fit it all on my screen there we go this is a little bit easier to see so here we go just by saying json on the end here i have extracted this json blob as a python dictionary so right now this is a python dictionary i see the curly braces around here i see the key value pairs right so here's my key here's my value all right cool um and it does have a bunch of metadata it has the year month and day where this came out all right looks like this is a fresh comic from uh just today um it has this image um now you'll note it did not send all of the pixel data of the image right i mean if if it sent all the pixel data of this image i'm not sure how big this picture is but um right that would be a lot i mean that's generally not something that we want our apis to send around we're trying to send this in a very concise way right so how big is this whole response right this is just plain text this is very small right this is this is a very small response so it's a very small amount of data to send across the internet um that's that's great um and the image right they did include the information that we would need to get that image but instead of sending us the red green and blue values for every pixel of that image um which which would be a lot they just sent us some text representing you know where this image lives and i'll just click on it and all right here all right cool we have today's xkcd comic this is this is the actual image this is what it looks like um so all right cool it's uh it's about logic gates um but all right cool this is this is uh today today's xkcd comic um all right cool um and we have the information to get it um even though when we ran this uh api call when we hit that endpoint it didn't actually send us that entire image right just you know i'll just say that the entire image is much bigger even though it's not that big i mean right when i clicked on it it you know fit on my screen pretty nicely it was pretty small um and it was all you know black and white not not very high res or anything but it was way bigger than the just the text here right text is just very very small for computers to to process and to pass around on the internet so cool cool we have this very concise response and now that i have this blob now that i have this thing i can pull out just the parts that i want let's just say that i want the date i want to know what date did this comic get released on um all right well i know how to grab things from a json blob i can grab the day here i'll ask to print this out and i can grab the [Music] here i'll just do it like this the month blob at the key called month and i can grab the year like i said a day month year probably not the format that you guys are used to at least i'm i'm in america i'm not used to this format all right but cool we can just look things up inside this blob based on their keys and get back the corresponding value awesome all right so here we've we've now actually used right we actually used a real api it was a very simple one sure um but we actually used the real api we got back some uh response turned it into a json blob well it already contained one but we just extracted that information from it and then pulled out just the pieces of data that we wanted all right cool cool so now now let's talk about how we're going to do the same thing with let's talk about how we're going to do the same thing with the twitter api so we could we could call the twitter api directly with get requests this is what we did with xkcd but we're not going to do that some more sophisticated some more sophisticated apis use wrappers and a wrapper is well exactly what it sounds like it is some way of saying okay well i know we're just sending you know get requests and as as we'll see with uh twitter post requests when we actually want to write tweets um i know we're just sending get requests and post requests requests around the internet um but um let's let's make this a little bit cleaner let's wrap it in um here um it's wrapped in the tweepy library um and the objects they're in um and these uh these wrappers are classes by that i just mean programmatic objects that have been written to streamline to streamline our using the api um so tweepy which i imported before but here let me just write this right now in case there were anyone anyone who joined us a little later um in google colab you certainly can just say import uh tweet the import some library and google colab will will go ahead and fetch that library now if we were doing this ourselves i'll just mention if we were doing this ourselves so we're not going to do this because um if you are doing this yourself you have to wait like about a week for for twitter to get back to you but we would end up creating a developer account on twitter not not just a normal you know human account but a developer account that's that's uh what twitter calls these um and um then we would have to get approved by twitter so this is the part where we would wait around for a week um we're not i'm going to be giving you guys my api uh key and private key as long as you guys promise not to post 50 000 tweets or you know whatever the whatever the record cap is um but anyway um so we would have to sign up wait around for a week um then if we were not doing this in google collab if you guys were trying to do this on your own machines on just your local machines um we would have to install this library um this library tweepy unless we wanted to you know just use the request library which would work but tweepy is just going to streamline things for us and then after signing up waiting around a week and downloading this thing then we would be ready to actually authenticate ourselves and and write some code so i've already done steps one through uh three for us well google collab did step three but i've already done those first steps um so let's just go ahead and get into how this thing is going to work so first first i want to mention the documentation so same thing we did with xkcd same thing we did before we don't know how the api works we have not seen this api before and all apis are different so how do we actually use it well here here i i have this page pulled up so here let me let me send this page to you guys in the zoom chat so this page is telling us okay how well you know what is what does the json actually look like when we try to interact with this api and here they're showing us what we can expect from this api's responses so this is for example i i believe a response for fetching a tweet here we have some information some keys right this this structure this structure hopefully looks familiar this is the same structure that we saw before we've got curly braces on the outsides we've got keys with a colon then their corresponding value which are comma separated from one another all right cool we've got one that was created it's unique identifier the actual text the actual text is probably what we're most interested in but there's plenty of other pieces of information we might want to fetch the name of the user or the screen name of the user some well i guess the place information is missing here this is just an empty dictionary um all right if it had any hashtags if it had urls i guess this one does have a url all right cool so here we're just getting a sense of what we should expect from these api endpoints that's not all that's not all i want to mention i'll also mention something new with the xkcd api we could only fetch data we could only ask to look at data with the twitter api we are also going to post data so in http there are get requests and there are post requests there are a few more but getting posts or probably covering the the main bases and if we want to actually send a tweet if we want to write a tweet we're going to go ahead and use post um and here it's just showing us you know all the different api endpoints though for us we don't have to worry about you know reading through these and typing them out because we're using tweepy so for us this is actually going to look more like this so here we go let me copy and paste this too into the zoom chat there this is the documentation page not on just the twitter api in general but specifically on tweepy and this is our wrapper this is our wrapper now it tells us a lot of things this page is you know very extensive i'm certainly not going to read through this whole thing for you guys i think that would be very boring and probably not all that helpful um but let's just see what this is going to actually look like i think you guys are perfectly capable of of you know reading through this on on your own time um but let's see what we can actually do um so i already have some authentication information we're gonna need this um so here we go um let me paste these very long unique tokens um into the chat as long as everyone promises not to spam a bunch of tweets through the bot um all right so i just sent you guys um that i know i know in the zoom chat it just looks like a bunch of gobbledygook but it is just these two lines well i guess three i get i think i did write this one as well but right it's supposed to be just these two lines um let's see um someone asked if we are following with our credentials um which are they exactly um yeah so if you're following with your credentials um let me pull up my documentation here it is um so this what i set as the access token this is the axis token and secret let me write this down so here um yeah when we call set axis token this is the access token and the secret access token and then on that first line so if anyone did already do this with their own own credentials here off handler um this is the um bearer token and secret bearer token so um for for anyone curious you know what why are there two of everything um one is the [Music] public token essentially you can think of that as your username um so it's the one that the twitter api recognizes and says oh yeah that's that's you know public information sure that's fine not really a big deal to to leak that out but this second one this is your secret token effectively your password right so so these are um what what we should really keep hidden what what should only be for us of course i'm sharing this one with with you guys um but all right cool this is how it's going to work this is how it's going to work so these are very just you know long looking hashes of things but all right if you did not in advance create your own developer account you'll just want to go ahead and use these so i'll just go ahead and run this all right so i imported tweetpian i ran this i'm not getting any errors okay cool let's just see how to um do some uh basic things with our um with our uh code here with with our um what what is effectively going to be a bot so probably the most basic thing to do sort of the hello world of um interacting with this api would be to see our timeline so here let's just see our timeline um i'm just going to call oh so so here i need one more line sorry i just pasted those two lines because those two were um the ones that had all that important information there please don't share those we're going to actually create an instance of our api wrapper this is going to be done by writing tweepy dot api and passing our authentication handler and here i have just named mine a uth auth oops i did not mean to scroll way up here there we go and i'm just going to store this in a variable called api so that i can say api.this and api.that later on all right now let me rerun this there we go i re-ran it and now the name of my particular instance um of my wrapper is just api i just called the api that seemed suitable now let's actually view the timeline i'm going to say api dot home underscore timeline with a pair of parentheses at the end and if i hit run here we're just going to see a bunch of a bunch of stuff whoa whoa look at all this this is not very pretty this is you know maybe our computer can make sense of this but uh you know i don't know about you but i am not having a good time reading this right this is this is a lot this is this is a lot of information that i don't really need um but hey what what format is it so okay sure they have some other stuff but then ah here they're telling us they have some json for us and here it looks like the same format that we saw when we looked at the documentation page he created that with a value for when it was created some unique ids etc etc well maybe i want to read through here and i just want to see the text of each of these tweets so here this is this is my timeline this i i think about 20 tweets the documentation would tell us exactly if we didn't feel like counting how many there are um but what we have for each of these um we can ask for its json in a slightly different way than before when we were doing this with the request library we would say name of the response dot json parentheses here we just use this a little bit differently or actually here this is um i'm trying to do it across all of these each one of these this is actually a list and we can see that with the square bracket at the very beginning and if i scrolled way way out or well i can't find it right now but somewhere there's a bracket way at the end there um so i'm actually going to loop through this whole thing if you're not familiar with for loops no worries so i'm going to loop through all of these maybe i'll comment that out so i don't grab it twice i'm just going to call each one of those individually tweet and inside of here i do have tweet dot underscore json once i've got just the json um i can or actually i think this is going to be i think i'm i'm um doing this right yeah there we go here i have just the json and now we can look this up one of these keys was text i i saw this in the oh there it is it's also right here let's just print the text of each of the tweets on my timeline and here we go i think i just made this uh account follow elon musk and rihanna um so here we go um all right we have a bunch of um tweets from elon musk and rihanna um i i did not ask it to also print which user is which so i i guess you guys can probably guess which ones are which but all right um here we go um we are just seeing the text for each of these tweets um i think it would be kind of fun to make this bot actually send some tweets in an automated sort of way so right now so far all we've done is we grabbed the timeline then we iterated over each of the individual tweaks in the timeline and printed out the text so so that's really all i did here um iterate over each tweet in the timeline printing out its text the text that that's all we printed out right there was all that other information in the json but here i'm just asking for the text let me go ahead and um i'm gonna paste this to you guys in the zoom chat um i hope this comes out all right um i know the the zoom chat makes things um kind of funky um but here i just wrote a little python function called pig latinify so this function will take a sentence and return the pig pig latin version of that sentence um so this is this is a pretty simple python function i guess this is you know this probably looks like a lot of code but i we don't actually know have to know how to read this thing i just want to show you that this will turn hello this is a sentence this will turn it into pig latin why not i think i think it could be kind of fun to have a bot that reads tweets from our timeline and ends up sending out its own tweets of excuse me of those same tweets but in pig latin why not um so here um here i have you know a bunch of these let me just grab one of them so here um let's just say this is one tweet or here i was asking to print it one tweet from our um or whatchamacallit um and all right marfeed um here it is just this tweet um i guess maybe a little morbid but uh all right um let's see if we can't piglettify this text so i'm just gonna call pig latinify on one tweet let's go ahead and hit run and there we go i i did make it get rid of any links so so that link that was in there is gone um but all right here i just used this little python function to turn this into pig latin if we want to make our bot send a tweet so here this is now my tweet this is a tweet that i want to make my bot send we can do this by calling so let's actually actually send a tweet now i've already looked at the documentation so i already know that i'm supposed to call update underscore status so this is how we can actually send a tweet in the parentheses here i'm just going to say status equals my tweet let's hit run and see what happens it's all right all we get back is this json but what actually happened that's right i didn't actually give you guys the um the twitter page yet let me just paste the twitter page that um if anyone if anyone has sent out tweets this is this is the page this is the page um where your tweets will end up going i just sent the link here in uh in us at the zoom chat and hey 21 seconds ago i wrote this tweet i wrote this just this little uh pig latin version of that of that elon musk tweet all right cool cool that's that's it that's that's that's my bot there um so you know maybe maybe you guys are not interested necessarily in um making a bot that prints out pig latin but that's okay we now have you know at our fingertips we now have you know the entirety of of python and i know some of you know know python already but um if you don't maybe this is a nice reason to start picking it up we now have at our fingertips a way to programmatically make this bot interact with twitter i guess i should probably mention one last thing that i have not done yet which is just how we could look up a specific user so so far you know i know the documentation is very extensive and it's got a ton of things you could do but so far all i've done is grabbed the tweets from my timeline um and then updated my status which i mean i just made it a pig latin sentence but um one thing that is just probably very common that you might want to do is let's actually look up a twitter user so here i'm going to say api dot get underscore user and here i can put um a screen name um i'm just gonna i don't know i'm gonna put spacex here i think that's probably a safe option um this is some user that i want to look up so i'm going to store the api response in a variable called user and then let's look at the json and here we go now this is a very large uh json blob i mean wow that there's there's a lot here there's a lot here but right it is all just plain text it is all just plain text but i i want to scroll up higher how do i get there we go i probably scrolled down too far um so just a plain text json blob with those uh curly braces around it and with any of these right and so we could we could look at particular things that we might want hey maybe i'll just pull out the description let's just look at the description and hit run and all right here we go this is this is just the description on the spacex twitter page very cool so with just knowing how to navigate python dictionaries um and right if you are doing this on your own to to actually sign up for for a developer account and and you know wait for for twitter to actually get back to you and say okay here's your credentials and a little bit of knowing how to use an api whether or not this is you know just a raw api or or one inside a library right here we were using the tweepy library um all right cool um we've got a way to write a bot um of course we were just doing this with twitter but um i'm sure uh if you guys wanted to you know do the same thing for um you know some different website that has an api right certainly not not all websites have apis um but another website that does have some documentation and um a an api right a programmable interface um for interacting with that site cool you've got the tools to do it um of course a different website would have a different api different rules for how you're supposed to interact with it um if if any do have their own wrappers right they would not use the the tweepy um library they would use their own whatever they've named theirs um and all right cool we we do have with just with just a little bit of code i i know you know here probably the most code i used was just for making something pig latin um but all right cool we've got our ways to actually write our own bot all right um then yeah thanks everyone for showing up i'm glad you guys got something out of this