1 00:00:01,240 --> 00:00:03,290 - Just as you can figure out 2 00:00:03,290 --> 00:00:06,280 who follows a particular Twitter account, 3 00:00:06,280 --> 00:00:09,280 you can also see for a given Twitter account 4 00:00:09,280 --> 00:00:13,320 what other accounts that account follows, as well. 5 00:00:13,320 --> 00:00:17,060 The so-called friends of that particular user. 6 00:00:17,060 --> 00:00:19,840 So we're going to do that via the friends method 7 00:00:19,840 --> 00:00:22,550 that belongs to the tweepy API object. 8 00:00:22,550 --> 00:00:26,400 That, in turn, is going to call the friends/list method 9 00:00:26,400 --> 00:00:29,000 that belongs to the Twitter API. 10 00:00:29,000 --> 00:00:32,040 Again, you'll get back a list of user objects 11 00:00:32,040 --> 00:00:36,300 in tweepy representing the friends of the specified account. 12 00:00:36,300 --> 00:00:38,050 Just like the followers method, 13 00:00:38,050 --> 00:00:41,256 you can get 20 of these folks by default, 14 00:00:41,256 --> 00:00:44,240 up to 200 at a time if you want. 15 00:00:44,240 --> 00:00:46,270 Again, you can call this method 16 00:00:46,270 --> 00:00:48,950 15 times every 15 minutes. 17 00:00:48,950 --> 00:00:50,940 By the way, just as a reminder, 18 00:00:50,940 --> 00:00:53,090 these rate limits could change, 19 00:00:53,090 --> 00:00:55,907 and in fact, as I was recording this lesson, 20 00:00:55,907 --> 00:00:58,840 I received a Twitter e-mail. 21 00:00:58,840 --> 00:01:00,920 A Twitter developer email update, 22 00:01:00,920 --> 00:01:02,620 that specifically called out 23 00:01:02,620 --> 00:01:05,490 changes in rate limits that are coming 24 00:01:05,490 --> 00:01:07,760 over the next month or so. 25 00:01:07,760 --> 00:01:11,010 So again, it is truly important that you're familiar 26 00:01:11,010 --> 00:01:12,180 with the rate limits, 27 00:01:12,180 --> 00:01:14,060 and that you keep track of that stuff. 28 00:01:14,060 --> 00:01:17,470 Especially if you're not going to take advantage of things 29 00:01:17,470 --> 00:01:19,800 like tweepy's automated ability 30 00:01:19,800 --> 00:01:22,540 to adhere to rate limit changes. 31 00:01:22,540 --> 00:01:24,990 Remember, this is an open-source project. 32 00:01:24,990 --> 00:01:26,970 When those rate limit changes occur, 33 00:01:26,970 --> 00:01:29,720 it is conceivable that tweepy, itself, 34 00:01:29,720 --> 00:01:32,340 may not be up-to-date yet, 35 00:01:32,340 --> 00:01:33,690 and therefore could have 36 00:01:33,690 --> 00:01:35,660 the wrong rate limits programmed in. 37 00:01:35,660 --> 00:01:37,301 So again, you really want to be careful 38 00:01:37,301 --> 00:01:39,150 with those rate limits. 39 00:01:39,150 --> 00:01:41,730 So with that said, let's go head back over 40 00:01:41,730 --> 00:01:44,590 to our current session. 41 00:01:44,590 --> 00:01:47,010 For this one, I'm going to create a list 42 00:01:47,010 --> 00:01:48,900 which we'll call friends. 43 00:01:48,900 --> 00:01:52,490 That's where we'll store all the friends that we get. 44 00:01:52,490 --> 00:01:54,990 Again, we'll setup a tweepy cursor. 45 00:01:54,990 --> 00:01:56,210 This time, we're going to call 46 00:01:56,210 --> 00:01:58,890 the API object friends method. 47 00:01:58,890 --> 00:02:01,750 Again, we're giving it the screen name NASA. 48 00:02:01,750 --> 00:02:04,610 Now because we're not specifying 49 00:02:04,610 --> 00:02:08,479 the number of user objects to get on each of the calls, 50 00:02:08,479 --> 00:02:11,660 we can get a maximum of 20 by default, 51 00:02:11,660 --> 00:02:14,435 but once again, just for demo purposes here, 52 00:02:14,435 --> 00:02:18,200 I'm only going to get 10 of those friends. 53 00:02:18,200 --> 00:02:21,480 So we're not actually going through pages of results 54 00:02:21,480 --> 00:02:23,751 in these simple calls that I'm demonstrating 55 00:02:23,751 --> 00:02:26,890 because of the fact that we're requesting so few. 56 00:02:26,890 --> 00:02:30,380 But let's say for argument's sake that we requested 100 57 00:02:30,380 --> 00:02:31,760 instead of 10. 58 00:02:31,760 --> 00:02:33,210 Then that would represent 59 00:02:33,210 --> 00:02:35,447 five pages of results by default 60 00:02:35,447 --> 00:02:36,800 because of the fact 61 00:02:36,800 --> 00:02:39,992 that it requests only 20 at a time by default. 62 00:02:39,992 --> 00:02:43,243 You can test that out on your own, as well. 63 00:02:43,243 --> 00:02:45,970 Just like we did up above, 64 00:02:45,970 --> 00:02:50,027 let's go ahead and create a concatenated string 65 00:02:50,027 --> 00:02:53,940 that contains all those friend account names 66 00:02:53,940 --> 00:02:56,860 and we did sort these alphabetically this time. 67 00:02:56,860 --> 00:02:58,500 By the way, there's no guarantee 68 00:02:58,500 --> 00:03:03,180 of the order in which those accounts come back to you, 69 00:03:03,180 --> 00:03:05,220 so every time you execute this, 70 00:03:05,220 --> 00:03:09,723 you're likely to get a different set of friends coming back.