- [Lecturer] Before we get into actually using
the APIs, it is important to get a sense of what
you are going to receive as a developer
when you make requests through the Twitter APIs
to get tweet-based information.
So what exactly is in a tweet from a developer perspective,
not from a user perspective?
So all the twitter API methods that we're going to be using
in general are going to return objects
in JavaScript Object Notation format or JSON for short.
This is a text-based data interchanged format
and it's extremely popular in web services.
It's the preferred way to send and receive objects
over the Internet.
All of the objects are represented in data structures
that look very much like Python dictionary,
so it's a familiar format to just about anybody
who works in the context of Python.
And most importantly it's both human and computer readable.
So the basic format of a JSON object
is a set of curly braces with property name
and value pairs separated by colons
and each key value pair is going to have a comma
separating it from the next one in the list.
If you want to do an array in JSON format,
it looks very much like a Python list does.
So simply a bunch of comma to limited values
in a set of square brackets.
And the nice thing about the Tweepy library is that
it handles the JavaScript object notation stuff for you
behind the scenes, so you don't have to figure out
how to do the formatting,
it will take care of all of that for you.
Now there's lots of properties in a tweet object
that you get back.
So every tweet, which is also sometimes referred to
as a status update contains a tremendous amount
of metadata that describes various aspects
of what's in that tweet.
When was that tweet created?
Who created it?
What are the hashtags inside that tweet?
Those are the words that start with pound symbol
or a hash symbol.
What URLs are in the tweet?
Are there mentions of other tweeter users,
which are known as @ mentions inside the tweet?
Are there any images or videos and other information
inside the tweet?
All of this and more is embedded inside
of every tweet object that you get back.
So here we have a table that lists a bunch of key properties
inside of a tweet object,
and of course in the online documentation for Twitter
they have details that go far
beyond what I'm showing you here
about what all of these keys mean
and what the format is of the data that is associated
with each of these keys as well.
So you can see when the tweet was created,
you can find what they call the entities,
which are all those things I was just listing
up above a few moments ago.
You can see the so called extended tweet information,
which is for tweets that
are in between 141 and 280 characters,
the new larger tweet format.
You can see how many times people favorited
a given tweet, which is kind of liking it on Facebook.
And you can also see if the user
has allowed Twitter to track their location,
the exact coordinates where the user was
at the time that the tweet was sent.
Now this is almost always null
because by default in Twitter,
they disable this and people have to opt in
to location tracking.
Some of the other key things you'll find,
the place that's associated with the tweet in anything.
So if somebody tweets about Time Square New York,
that will automatically get turned into a place object.
There's an ID for the tweet that's an integer
and there's also a string representation
of that ID as well, which is the one that Twitter
actually recommends using if you ever need an ID.
There's the language of the tweet.
So for example, en for English or fr for French.
And we'll see some of that here in the examples
later on in this lesson.
How many times the tweet gets retweeted,
meaning somebody sent it again.
So if you ever see a tweet that has the letters RT in it,
RT at the beginning of a tweet means that it was retweeted,
and that's actually a tweeter reserved word, if you will,
to indicate the concept of retweeting.
And there's several such words like that.
The text attribute is going to tell you
the text of the tweet in 140 character or less format.
If it's an extended tweet, it will actually show you
or give you back a truncated version
of the extended tweet, excuse me.
And then separately, it'll give you a user object
that represents who posted the tweet in the first place,
and user objects themselves also have key value pairs
within them of a additional information.
Same thing is true up here with the place object as well.
So here we have some sample tweet JSON that we've embedded
into this page that I'm showing you at the moment.
And this is an actual tweet that we pulled off
the @nasa Twitter account back
when we were writing the book.
Some of the fields are not returned with every single
object that you get back, so it depends on which API
method you are calling as to what you'll actually get back.
So some where in every tweet object,
some where only in certain tweet objects,
and all of that information is explained
in the online documentation.
So this particular tweet that I showed you up above
was created originally on September fifth of 2018.
This is the ID information for the tweet.
The strings are more portable which is why
they generally recommend using strings
for interacting with tweet IDs if you need them.
This is the original text of the tweet.
Sometimes you'll see a dot dot dot notation in the tweet
indicating that a portion of the tweet
was chopped off because it couldn't fit
in the 140 character limit.
And that limit, by the way, includes things
like the URLs and the hashtags and other stuff
that shows up in the tweet.
If it was truncated, it will tell you that.
Then we have this entities key.
And in the entities key you can see
a collection of hashtags, a collection of user mentions,
a collection of URLs.
We tried to format this to make it a little bit more
readable for your own purpose.
As you scroll down you can see whether it was replying
to some other tweet, who the user was.
And these are a whole bunch of pieces of information
about that user.
So in the case of NASA, they, at the time,
had over 29 million followers of that particular account.
And there are Twitter users who have over 100 million
followers nowadays as well.
As you scroll through here, or as I scroll through here,
you can see there's all sorts of information
that you have access to on a tweet by tweet basis.
So lots of different information that you can take
advantage of as you work your way through the Twitter APIs
and learn how to use them.
So there are some Twitter object, JSON object resources
that you should be aware of.
So the complete list of all the tweet object attributes,
if you go to this URL that you now see
in the address bar or if you just search for this
on the Twitter developer website using
the search field up here,
this is a complete description of everything
that you'll find in a tweet object.
By the way, they'll often have an overview tab
that gives you a general overview and a Guides tab
that gives you a lot more detail on how to use
particular APIs for instance.
Going back over here, you'll also want to see the details
that have to do with the switch from 140 to 280 characters.
So that's what are called extended tweets.
And this is just lowered down on the same page
I was showing you.
And then finally there's a general overview
of all the JSON objects that the twitter APIs return
and links to the specific object details.
You can find that also at the Tweet Objects page.
It looks like they redid that URL to point to this page
since I had originally created that.
So with that said, next up we're going to talk briefly
about getting Tweepy installed
and then we're going to jump into the source code.