- Just as you can figure out
who follows a particular Twitter account,
you can also see for a given Twitter account
what other accounts that account follows, as well.
The so-called friends of that particular user.
So we're going to do that via the friends method
that belongs to the tweepy API object.
That, in turn, is going to call the friends/list method
that belongs to the Twitter API.
Again, you'll get back a list of user objects
in tweepy representing the friends of the specified account.
Just like the followers method,
you can get 20 of these folks by default,
up to 200 at a time if you want.
Again, you can call this method
15 times every 15 minutes.
By the way, just as a reminder,
these rate limits could change,
and in fact, as I was recording this lesson,
I received a Twitter e-mail.
A Twitter developer email update,
that specifically called out
changes in rate limits that are coming
over the next month or so.
So again, it is truly important that you're familiar
with the rate limits,
and that you keep track of that stuff.
Especially if you're not going to take advantage of things
like tweepy's automated ability
to adhere to rate limit changes.
Remember, this is an open-source project.
When those rate limit changes occur,
it is conceivable that tweepy, itself,
may not be up-to-date yet,
and therefore could have
the wrong rate limits programmed in.
So again, you really want to be careful
with those rate limits.
So with that said, let's go head back over
to our current session.
For this one, I'm going to create a list
which we'll call friends.
That's where we'll store all the friends that we get.
Again, we'll setup a tweepy cursor.
This time, we're going to call
the API object friends method.
Again, we're giving it the screen name NASA.
Now because we're not specifying
the number of user objects to get on each of the calls,
we can get a maximum of 20 by default,
but once again, just for demo purposes here,
I'm only going to get 10 of those friends.
So we're not actually going through pages of results
in these simple calls that I'm demonstrating
because of the fact that we're requesting so few.
But let's say for argument's sake that we requested 100
instead of 10.
Then that would represent
five pages of results by default
because of the fact
that it requests only 20 at a time by default.
You can test that out on your own, as well.
Just like we did up above,
let's go ahead and create a concatenated string
that contains all those friend account names
and we did sort these alphabetically this time.
By the way, there's no guarantee
of the order in which those accounts come back to you,
so every time you execute this,
you're likely to get a different set of friends coming back.