Press "Enter" to skip to content

Twitter API Trainwreck (worst disaster ever)


um the episode that you’re about to see
is going to be it’s probably the worst
episode in fun fun function history we
do a pair programming session where we
fail so incredibly bad that it just
redefines failing on these things and to
add insult to injury I also managed to
delete the footage of my main camera
that one that you’re looking at right
now that it’s normally the one so
instead of canceling the episode I
because just keep uploading the show
must go on the creed of a youtuber I
have bought this plush animal – plush
plush plush animal to replace me during
during the episode so we’ll see how that
goes good Monday morning today we are
going to do a pair pro pair programming
session where we play around with the
Twitter API to mine out a lot of replies
from tweets and dad let’s see how it
goes hi mmm PJ and I’m David I’m here
and you are watching fun fun function
better better better better better
prepare today’s sponsor is brilliant a
problem solving website that teaches you
how to think like a computer scientist
if you are interested in computer
science fundamentals binary trees
quicksort Big O and that kind of stuff
instead of you just passively listening
to videos brilliant gives you these
interactive challenges of increasing
difficulty so using brilliant is kinda
sort of feels like a game is very
satisfying use brilliant org slash fun
fun function when you sign up that tells
them that you came from here and it also
gives you 20% off the annual
subscription if you are one of the first
200 people so run or over all this info
is also in the episode description okay
it’s time for fake can God already oh
we’re gonna do a lot of features in this
episode let me get some Brouilette did
you know that there are both like that
the Twitter API has like different tiers
what a premium an enterprise are you
kidding me
like no for it yeah I guess what are the
differences I don’t really care
well you you do if if it’s yeah but what
we’re gonna do can possibly be it
like let’s let’s instead explain what
fee K is actually I don’t know I don’t
know what you’re aiming for
I guess because just if you’re working
at a big Swedish traditional
organization a University Volvo IKEA
whatever you have fika regular coffee
breaks at least one in the morning and
one in the afternoon and the whole
purpose with the fika is well I don’t
know what the purpose is but the culture
of the Freak is that everyone gathers
and during those 15 minutes they have
coffee and eat cookies and eat candy
albula
together and it can often be a pretty
strange setting that you’re like say if
you knew at work you’re 10 people just
sitting in a big circle
eating coffee and discussing random
shits like what the weather was like or
what do you want to do in your summer
cottage or god forbid what your kids
were doing this morning and how awful
they were and blah blah blah blah blah
it can be really really bad but it’s
also pretty good to integrate new people
into the organization I guess yeah it
creates like this interesting natural
flow and it also creates like which
forces you out of work mode for a little
bit which is why what we’re gonna what
we’re gonna do use it for here because
we found that in these pair programming
episodes we tend to get a little like in
the zone and get
it’s stuck so what we’re gonna do during
like our fika session is to reflect on
what we just did since the last speaker
because we’re gonna do a lot of Neth in
this episode we’re compressing like a
full workday into one hour and then so
we’re gonna reflect and then we are
going to use a little bit think a little
bit about it and then we are going to
plan ahead what we’re gonna do in the
next session until the next speaker and
we’re gonna work like that and see how
that goes
yes so we start by setting a timer for
10 minutes so we are going to build
something with the Twitter API in one
hour – the five minutes we just had for
fika yeah exactly
yeah their feet guys like that is
allocated but we are forced to take the
picket we’re not allowed to work you’re
in the figure which is an important
concept of this because it’s it has like
its it has this very strong you know
worker what’s it called Union heritage
and we think that it will be beneficial
for the project that we actually
accomplish more by having by working
less yeah precisely I it’s gonna make us
more focused now so I have I had this
problem last week last week we published
the first of the interviews that we did
at Nordic yes because I were hopes I was
hosting J Nordic s and we were allowed
to set up this interview booth and talk
to whatever speakers that we liked
turned out really well and I wanted to
do more so what I did was and I did this
did this tweet where I asked where is it
who is your favorite speaker that you’ve
watched at a conference in the last 24
months
please use likes and he replies in the
Shred if someone has already replied
with your favorite and I got a ton of
retweets a ton of likes and a lot of
comments and we I really don’t want to
go through this manually because that
will make me die and of course like of
course the input is not clean here like
people did not follow this this
requirement people like often added to
some of them have likes and you know you
see here it’s like a ton of them and
they it’s not like it’s a lot of text
mixed in yeah you get it like we’re
gonna so we’re just gonna extract the
names the tweet names yeah
and perhaps a counter to say how many
times do we what we can start by just
trying to extract a list of the names
all right yeah let’s do that
keep it simple stupid one step at a time
like so that’s what we put here like
extract a list of names or perhaps even
further like just can we scoop it even
further down even simpler just extract a
list of the replies to this tweet where
do I go in this can you give me a link
to the documentation so that we can have
a look at this okay so here I don’t
understand you’re just going to search
tweets like this do whatever just click
somewhere okay like I’m so annoyed with
this space I have to put something here
animated gifs please I’m not very much
on Twitter is that what it’s called a
timeline a timeline is simply a list or
an aggregated stream of tweets the
Twitter API so so it’s home time running
used this is probably like the their
equivalent of the newsfeed oh here are
those things standard premium and
enterprise yeah and I think premium we
can apply as a developer and then enter
price you have to pay for it I guess
can’t you just go get how to get like
it’s gotta be tweet objects here what is
this free turd interrupting tweet Jason
hang on post retrieve and engage with
tweets returns are fully hydrated tweet
objects for up to 100 tweet per request
as specified by comma separated values
passed to the ID parameter that sounds
like what we want right take a break
okay I will go go and fetch my mic-n al
ghul mm-hmm okay reflection what have
you learned
all right we learned a little bit about
what the Twitter API has called stances
and very some premium that it’s the API
is tiered I’m surprised by that
oh it made its first quarterly profit in
its history this year oh yeah
no I think perhaps that’s what’s
when they launched the developer API
priced here yeah like it’s not a
completely dumb idea actually to charge
for that because it’s it’s actually a
genuine value that they provide to
probably to people that are willing to
pay for it people are absolutely not
willing to pay to publish their content
on someone’s platform that’s not gonna
happen okay timer is set cool so what is
the plan the plan is to curl the example
request and see what we get just gonna
do this example with requests straight
away here how do you do is curl this is
it bad authentication data make sense we
need probably some kind of headers I’ve
used am using a separate profile for
fire fashion so that they don’t see all
my absolutely insane browser
history we’re sign-in apply apply for a
developer account oh I really hope that
this is immediate describe in your own
words what you are building trying to
extract what people thought about my
tweet my tweet it would be great if you
just had one tweet must be nice oh my
god oh my god you have so great I’m sure
that nobody does this of course not
everyone does this this is why they have
the enterprise tier because they have to
pay someone to read all this yeah good
god like why do you do this like who
believes that people do this when
they’re starting to play out with an API
like Twitter really like nobody nobody
knows what they are doing when there
Oh God click now when the next box no I
don’t even if I don’t even know what it
said
it just is agree yes yes I’m the
Navigator agree yes yes yes I know I
clicking this box you indicate that you
have read and agree but I can’t click
the box I’m trying to click the box you
idiot proof okay now can I kick the box
yes
oh go on subscribe no no no this is your
fault
you tell me you told you to click the
boxes yes I did I will forward all their
spam thank you ok yes and then I will
forward them back and then we will have
a small infinite loop of forwarding
application on the review thanks we’d
receive your application and we are
reviewing it we’ll be in touch soon are
you kidding me no I just click I click
apply so you literally don’t get a API
immediately for the API
Twitter really but I hang on hang on I
have an old app here which keeps
otoscope I lose it brilliant Christa
this is going straighter so how do we
use this to access stuff Oh off with the
Twitter API but we don’t want that I
want like can I just do the like we
really don’t want to create a entire
authentication flow usually like an API
worth its salt has some kind of service
key access token and access token so you
could create I think you can just make a
header that says authorization and then
you add Baro
and then your key and so it’s like bare
error and yeah invalid or expired token
let’s try to paste in all the tokens
perhaps should we ok this was my first
guess perhaps this that’s not right I’m
gonna your school will its Twitter bear
oh we need to get a bearer took it first
take a break I’m back thank God for
freaked out like like was so boring
look I really hate like mining and like
figuring out how ap ice work it’s the
same thing for each pair programming
video we always get stuck here I mean
when it comes down to it this is
development no hang on we have to say
what happened
oh yeah what happened yeah what happened
we we ran into problems because it said
that we weren’t signed into something
exactly yeah which is okay because we
weren’t know and we tried to like find
some kind of service key for like
usually like I’m used to the Google API
is having a yes JSON dump that you can
just shop in and then you get access but
for Twitter and we found out that you
have to use your seek like your clients
pee token and secret stuff and then get
a token and then use that one okay so
the next step is to use our secret to
something to get the bearer token and
then we can use the bearer token to do
what we want to do right super knowing
that this API yesterday public sorry
come in why can’t they of exposed like
getting tweets by Jason that would be so
like that wouldn’t hurt them one bit
yeah and they could just limit it
somehow that you can only do like I
don’t know 10 requests per hour or
something just to get people started no
no I mean if I wanted to be out I would
just scrape their HTML yes give me not
developer friendly but then again like
this show is like 25% me complaining
about how other people should have
solved my problems I’m sure they have
their reasons when it comes down to it
it doesn’t really matter it’s our job as
developers to like okay we have a
problem and then you wait but it’s our
job to slam or heads against it until
this bit is solved so should we get back
to work
oh god we have to encode this there
has to be an NPM module for this NPM
really
yes yes they did this is what we’re
gonna use we should have used this for
miss start no I don’t agree we shouldn’t
have started by just our product by like
Oh is there an NPM module for this I
think we did it in the right way yeah
that’s true like because we have gotten
stuck multiple times on with that like
and then found an NPM module that was
way too complicated and you’re
absolutely right stuff look Jess I’m so
good at naming so just a small shout out
if you’re here and think that we will
succeed with this go to some other
channel like I don’t know West boss or
the coding train or traversing media or
not dev tips we’re running their flips
now we won’t succeed with anything go
somewhere else and never come back
we won’t find we will never finish this
finish this channel it’s not about
success this channel is about failure
yes I just blindly copied the entire
like the first code block I found on the
npm module because it kind of looked
like intuitive to what we need it like
it has this twitter the crate and then
it does this client and then we stuff in
all the secret cool and then paste
the pasty face and these things I
suppose God so much of development is
just copy pasting things from a location
to another location this is also the
best type of content like tune in every
week and seeing these two guys like
installing the same things in special
studio code again and again and again
over and over and over what they call
like the three yell like the children’s
show with the three weird space animals
in suits that they go lalala lalala
lalala the thing with Teletubbies is
that it constantly repeats all the time
because small children like repetition
and developers also do that as well I
think that is where you’re all
developers are also small children there
we go
alright alright yes BAM yes yes boom
worked
that’s the SIS and then something I have
lost this just back up there in that
browser window come back in this one oh
yeah good ah
back back back back back back back
they like repetition dude get starts a
show idea is used to retrieve a single
tweet object do you see how much falcon
site I had like I asked I saw that
immediately yeah that is just API ghetto
to do let me grab is this here this boom
mmm we got it yeah brilliant
there our lens what does it have in
entities I suspected its entities that
has the good stuff what you wrote the
module yeah I wrote a module it’s called
to something like sniff they are super
safe ok I don’t know what you’re doing
right now
no no so what this does is that like
this tweets thing like this is really
hard to read in this thing so I just
want to write it to a file and that is
what I’m using this for so I’m just
gonna call it API output Jason which
just happens to be a really good name
actually and then I’m gonna just dump
tweets in here just happens to be a good
nice do you see how nice this is
it’s a search or documentation top left
can we search for that replies direct
messages this is the worst search
results search standard search API in
reply to status ID you can get a list of
all tweets that were in replied to that
ID I’m gonna google it Twitter API
replies do you tweet 30 seconds before
it’s time for coffee and Cannell blank
god get replies forgiven twitter search
api do not watch this video what should
this fish missed we’re done okay okay
okay
what did we do what did we manage to do
since the last week out get a PR you up
and running with the keys and stuff yeah
we did so it actually sort of it we
actually now have
some some outputs and we also used my my
awesome library super sniffer which
basically is just a thing at you right
okay I was at a time in our let’s get
back to work okay so what’s the plan now
okay we want to find okay we want to
find out we’re gonna get the replies of
this tweet because we managed to we
managed to access the end point but the
dick like just grabbing the tweet
doesn’t work because that doesn’t give
you the replies because the the data
architecture of Twitter is when you
think of it insane no but when you think
of it it’s like a relational database
like no that’s exactly how it’s not know
but it is we so for that tweet like it
makes more sense that other new tweets
added to the database okay so we should
be done now but let’s get stopped okay
no but it makes sense because think
about the database thing yeah if you
have a database and you have a row or an
object in the database it doesn’t make
sense that once you get like a viral
retweet storm that you have to update
that original object each and every time
I mean an array makes a lot of sense
that would be like from a distributed
standpoint that it is excellent it’s
actually horrible Twitter we still think
you should be like Google but in this
particular case you did something that
we sort of can understand you can use
the search api for the app user name of
the author go through the results
looking for the in reply to status idea
to compare the ids but I have like a hot
Chilean kabillion replies using the API
search method query the following use a
at user name since ID tweet ID and
retrieve all sweets since tweet ID
mmm-hmm yeah but but if you tweet it
afterwards you would get those as well
right okay so like this API is like a
ludicrous pile of shite now we litter
we have to use like the search to find
tweets that are replies to me since the
tweet and then we’ve had to fill out the
tweets that are later so basically this
thing will be slower and slower and
slower a flight you know what we should
do give up no actually what you said in
the at the start I think that’s the best
approach this we should just scrape the
the web and just scroll through I write
a small jQuery hack to just get all the
items I think it’s actually simpler than
this go I think I think we should have
googled Twitter scraping instead yeah we
should have because the like I could not
have believed that this API was this
atrociously god-awful he dumb but we are
out of time we are literally out of time
we did not absolutely completely fail in
this I even failed I haven’t even
finished David this was not her fault it
was okay maybe it was okay David it
wasn’t our fault
but it it was still a responsibility if
you’re watching this and you work for
Twitter as a developer could you please
just ask around why is this why is it so
hard we’ll enterprise tier solve it we
will get the enterprise that we want to
just get it in a nice fashion I would
really appreciate to see someone
answering why it’s like that it’s like
when we met YouTube and we had many
questions you and I Mateus about why
YouTube’s API sucked so bad and they
basically said that it was just old
infrastructure that what we wanted to do
like they couldn’t do it because it was
just so old and they were building new
things and it just wasn’t possible
perhaps wheter is the same that they
just rely on this really really old crap
someone built in PHP 10-15 years ago I
don’t even remember when 1213 years ago
when whenever Twitter soared
I would like to know the reason because
there is no
it’s not logical and it should be a
pretty basic use case right friends
between Google and Twitter here though
is that Google has a bunch of other
products like this is literally they’re
like this is the only thing they do they
have one job 12 years no profit yeah
that’s like an indicator deserve any
profit they need to like do actual work
and produce actual value in order to get
profit that’s why they don’t have okay I
feel that we can it I’m pretty sure that
you can clickbait this title because
we’re so bashing on twitter yeah okay
yeah you should also watch the Jonathan
Blow talk worried but like matches on
Twitter it talks about how they based
like they have an insane amount of
engineers are not doing any work but
then the next video I think we should
just watch that talk together I’m just
on livestream with all their patrons and
everyone the thing with that talk is
that he also ships on the web web
companies in general he has things that
the web is just atrocious and javascript
instance Trojans then we can shade on
him I guess save it what did we learn
nothing treat it like a nobody
it um this could probably be done I
think like we just got to do that thing
with the weird Search API thing it’s
just weird that you have to do it was
that we thought that this was so we
thought that it was a very simple task
that that this was just something that
would come out of the box of the Twitter
API and I think that was our big mistake
we sort of assumed that this would be
logical because I can see you here on
your screen there’s get get get get get
post post post post post get like
there’s so many things you couldn’t do
and we thought that this would be one of
the basic things to do because it was
the only case that we saw like it was
our case and of course our case is the
most important one it was fun though
you know nah it was it was it was fun if
you like pain speaking your pain I I
feel
pain in my stomach I’ve eaten too much I
feel like they were excellent I like
this new format where I can rationalize
eating tons and tons of cinema months
you know what I even expense the
cinnamon buns
did what David it’s like the accountant
of all of us to like he makes sure that
I don’t buy crazy stuff like I used to
do at night all companies at home don’t
have a video about that when you crash
your old company no I actually don’t I
don’t talk too much about myself on the
show ironically I guess you sort of talk
a lot about yourself in private yeah
like I figured that people are
interested in in code you know shall we
talk about our sponsor yet again yes
brilliant at org be one of the first 200
people that sign up in you for the
Android subscription we have 20% off yes
brilliant org slash fun fun functional
it’s all in the episode description you
should check them out they’re really
really great I like him a lot
could I have one final request can you
increase the size of those dogs go out
of this will bang oh yeah dogs dogs dogs
dogs dogs oh pretty cute
we’re not sponsored by JP but if your
work for Jeff and want to be sponsored
we’re sponsored by dogs and brilliant ok
should you do an outro you have just
watched an episode of fun fun function
we release these every Monday morning
oh wait hundred GMT but you will forget
that so you can subscribe here like
clicking here or you’re gonna watch
another episode right now by clicking
here
I am mpj and I’m David until next Monday morning stay curious
Please follow and like us: