1
00:00:02,029 --> 00:00:07,160
Hi, welcome back on Facebook, that's the topic of this video.

2
00:00:07,700 --> 00:00:17,120
What will specifically do in this video is willing to access dots of Facebook profiles via Python.

3
00:00:17,660 --> 00:00:21,860
And we're going to do that using the official Facebook API.

4
00:00:22,790 --> 00:00:30,410
So you are going to learn how to use the Facebook API from within Python so that you can batch access

5
00:00:30,770 --> 00:00:38,060
data from profiles such as getting their photos and videos and posts, access and comments.

6
00:00:38,930 --> 00:00:45,800
But this is not about hacking, so we're not going to access data for which we don't have permission.

7
00:00:46,430 --> 00:00:54,830
So, for example, if we get photos from a Facebook account, we can only get those photos if those

8
00:00:54,830 --> 00:01:02,900
are public or our accounts and that account are connected as friends and those photos are visible to

9
00:01:02,900 --> 00:01:03,680
friends only.

10
00:01:04,129 --> 00:01:10,280
So again, this is the official Facebook API that means everything is done according to the rules.

11
00:01:11,300 --> 00:01:18,770
The benefit is that with Python, then you can create your own apps by accessing Facebook data, and

12
00:01:18,770 --> 00:01:23,690
then you can use those dots as your wish in your Python program.

13
00:01:24,500 --> 00:01:26,450
So get ready and let's do this.

14
00:01:26,840 --> 00:01:33,320
The requirements for this is naturally a Facebook account, so you should have a Facebook account.

15
00:01:34,920 --> 00:01:41,300
And so you should be logged into that account in your browser and then Google Facebook developer and

16
00:01:41,300 --> 00:01:45,380
then click the first results, which should take it to developers dot Facebook dot com.

17
00:01:45,710 --> 00:01:53,840
What we'll do here is we will create a developer account for Facebook, so that allows us to access

18
00:01:53,840 --> 00:01:56,060
Facebook data programmatically.

19
00:01:56,600 --> 00:01:58,760
So using the Facebook API.

20
00:01:59,690 --> 00:02:02,240
So once you go to that page, go to get started.

21
00:02:03,920 --> 00:02:08,990
And then you want to follow this process, what do you want to register as a developer?

22
00:02:10,520 --> 00:02:17,570
You do need to enter a phone number in here in this step, I need to answer my phone number, so please

23
00:02:17,570 --> 00:02:18,300
do that as well.

24
00:02:18,320 --> 00:02:23,870
It's a requirement to have a Facebook developer account, so I answer my phone number.

25
00:02:23,870 --> 00:02:26,360
I receive a code through an SMS.

26
00:02:26,900 --> 00:02:30,350
I enter that code to the form in here.

27
00:02:30,680 --> 00:02:38,540
So I verified my phone number and then I also confirm my email address as the form asks me to do.

28
00:02:39,140 --> 00:02:40,970
Now we are on this step here.

29
00:02:42,110 --> 00:02:47,990
So which of the following describes you, well developed were so prescient, pleads for registration,

30
00:02:47,990 --> 00:02:51,710
then that should take us to this page.

31
00:02:52,160 --> 00:02:54,710
So now we need to create an app.

32
00:02:54,950 --> 00:02:58,790
So this is how it works with Facebook any time you want to do something.

33
00:02:59,060 --> 00:03:02,390
It means you want to build an app for Facebook.

34
00:03:02,390 --> 00:03:04,310
So and that's what we're doing.

35
00:03:04,310 --> 00:03:12,110
So we want to access some photos or posts or comments from a Facebook profile, which we have access

36
00:03:12,110 --> 00:03:12,500
to.

37
00:03:13,040 --> 00:03:14,030
So create an app.

38
00:03:15,900 --> 00:03:17,280
I'll choose none here.

39
00:03:18,120 --> 00:03:23,580
This is mostly for Facebook statistics, they want to know what you're using these things for.

40
00:03:24,420 --> 00:03:31,080
So for display name, put something or that's up, for example.

41
00:03:31,620 --> 00:03:35,860
And then that's the email address of.

42
00:03:36,240 --> 00:03:37,800
Press on, create up.

43
00:03:39,080 --> 00:03:43,970
Re enter your Facebook password, so this is a password of your Facebook account.

44
00:03:51,780 --> 00:03:55,800
And that should take us to these dashboards of our app.

45
00:03:56,070 --> 00:03:58,950
So you see all this app is selected in here.

46
00:03:59,850 --> 00:04:01,830
Those are all the settings.

47
00:04:03,830 --> 00:04:04,970
Of my app.

48
00:04:06,470 --> 00:04:10,280
The next thing we want to do now is to create an access token.

49
00:04:10,730 --> 00:04:19,820
So go over to this header, so click there to go to the very home page in here and then go to more.

50
00:04:21,440 --> 00:04:27,140
And then go to tools and then go to Graph API Explorer.

51
00:04:27,290 --> 00:04:32,000
So Graph API is the name of the Facebook official API.

52
00:04:34,460 --> 00:04:36,620
That should take you to this Web page.

53
00:04:37,910 --> 00:04:45,230
Now make sure that in here on the Facebook app, your app is selected, so all its app is the name of

54
00:04:45,230 --> 00:04:47,210
the app that I created a minute ago.

55
00:04:48,570 --> 00:04:55,040
And then you want to generate an access token, so press and generate access token and then you want

56
00:04:55,040 --> 00:04:58,190
to give access permission to your app.

57
00:04:59,660 --> 00:05:07,310
So Facebook is making sure that you, as the owner of your Facebook account, are giving permission

58
00:05:07,310 --> 00:05:11,000
to this or this app, the new app.

59
00:05:12,920 --> 00:05:20,510
Now we do get this message here, which is a security feature or Facebook.

60
00:05:20,570 --> 00:05:27,380
So because my Facebook account Ace New, I just created this account exclusively for this lecture,

61
00:05:27,380 --> 00:05:30,110
I didn't want to use my main Facebook account.

62
00:05:30,530 --> 00:05:37,370
So this new Facebook account, which was created just ten minutes ago, can not work with new applications.

63
00:05:37,370 --> 00:05:44,330
So I need to wait 60 Minutes and then I can go back here and generate that access token.

64
00:05:44,840 --> 00:05:50,270
So if you also have just created your Facebook account, then you also need to wait.

65
00:05:50,270 --> 00:05:52,190
So maybe do some other videos in the course.

66
00:05:52,490 --> 00:05:55,820
Otherwise just continue and follow this video.

67
00:05:56,960 --> 00:06:04,100
60 Minutes have passed, so now I have access to the Graph API explorer interface.

68
00:06:04,670 --> 00:06:08,630
So what is this and what can we do here?

69
00:06:09,320 --> 00:06:16,820
Well, this is the interface of graphical interface that we can use to interact with a graph API explorer

70
00:06:16,820 --> 00:06:17,870
of Facebook.

71
00:06:18,590 --> 00:06:22,670
So using this interface is one way to interact with the API.

72
00:06:22,850 --> 00:06:25,130
Another way is to use Python.

73
00:06:25,880 --> 00:06:32,780
Both this interface gives us some key data that we need, and then we can switch to Python.

74
00:06:32,990 --> 00:06:34,880
So let's explore this interface first.

75
00:06:35,090 --> 00:06:35,900
What do we have here?

76
00:06:35,930 --> 00:06:37,490
Well, we have the access token.

77
00:06:37,910 --> 00:06:43,100
This one in here, you can press the button to copy it and put it in your Python script.

78
00:06:43,130 --> 00:06:44,150
I'll do that later.

79
00:06:44,600 --> 00:06:50,240
For now, it's important to know that you need to be careful with this access token where you put it,

80
00:06:50,480 --> 00:06:54,500
especially if this is your main Facebook account.

81
00:06:54,770 --> 00:06:57,200
For me, this is just a throwaway account, so.

82
00:06:58,520 --> 00:07:03,830
This just by phone, is how I described this, as I told you, so I'm not going to worry much about

83
00:07:03,830 --> 00:07:10,730
that, and I'm down here, you have the ad that we created the API app.

84
00:07:11,180 --> 00:07:13,100
So are this app in my case?

85
00:07:13,720 --> 00:07:19,310
No, this indicates if you're working with a user accounts or a page.

86
00:07:19,520 --> 00:07:25,880
So we have Facebook pages and we have user calls here we are working on Facebook user accounts.

87
00:07:26,210 --> 00:07:29,870
So this should be user token here and then we have permissions.

88
00:07:30,170 --> 00:07:36,290
So currently we only have permission to the public profile of this user.

89
00:07:36,290 --> 00:07:44,660
Accounts by phone is how, in my case, that to me is the API can only access posts and photos which

90
00:07:44,660 --> 00:07:45,770
are public.

91
00:07:46,160 --> 00:07:50,220
For example, this posting here is not public.

92
00:07:50,250 --> 00:07:51,830
This is shared only with friends.

93
00:07:51,830 --> 00:07:57,590
Therefore, with this permission, we cannot access that post.

94
00:07:58,100 --> 00:08:06,140
Therefore, what we want to do here is search for user posts and presence and also you want to give

95
00:08:06,140 --> 00:08:08,690
access to photos, so user photos as well.

96
00:08:12,430 --> 00:08:21,100
And leave them there, once you have done that, then you need to press again on generates access token

97
00:08:21,970 --> 00:08:25,600
so that you gets a new token for those permissions.

98
00:08:26,170 --> 00:08:32,740
Right now, you see that these are not green anymore, so they have been added to permissions.

99
00:08:32,960 --> 00:08:34,240
And this is a new token.

100
00:08:34,240 --> 00:08:39,280
So that's the new token you need to use now if you want to access user photos and user posts.

101
00:08:39,549 --> 00:08:44,440
That token is different from the previous form, so you can discard the previous token.

102
00:08:44,710 --> 00:08:45,460
Don't use it.

103
00:08:45,850 --> 00:08:47,930
Then we jump into this area here.

104
00:08:47,980 --> 00:08:48,700
Let me zoom in.

105
00:08:50,050 --> 00:08:54,730
We have this URL are a mixture moorfields equal I.D. common name.

106
00:08:55,090 --> 00:08:56,560
And I'm going to press submit.

107
00:08:57,310 --> 00:09:05,890
So what I did now is I performed a query to the API and we got back some data on what is this, what

108
00:09:05,900 --> 00:09:07,870
we have the I.D. and we have the name.

109
00:09:08,830 --> 00:09:12,670
The I.D. is the user I.D. of my Facebook account.

110
00:09:12,700 --> 00:09:20,450
So all Python is told and that this is a name that vets use it to contest in.

111
00:09:20,620 --> 00:09:26,200
In your case, it could be your Facebook name and surname or whatever you have in your Facebook profile

112
00:09:26,200 --> 00:09:26,500
name.

113
00:09:27,130 --> 00:09:33,160
So we just quoted some data with this query, but we did that through this interface.

114
00:09:33,160 --> 00:09:36,400
So how can we do the same via Python?

115
00:09:36,850 --> 00:09:44,200
Well, to do the same via Python, you need to go down here to get code presents and then you have different

116
00:09:44,200 --> 00:09:50,530
types here, so you have JavaScript implementation of this.

117
00:09:50,710 --> 00:09:58,990
But what we need to do is go to see your URL and then copy that entire thing.

118
00:09:59,230 --> 00:10:08,710
So right click copy or control, see and then go to Python and I'm going to import requests first.

119
00:10:08,740 --> 00:10:15,760
That's the Python third party library that allows you to make a request to the Graph API explorer.

120
00:10:15,910 --> 00:10:22,180
So in the case of the VA interface, this interface makes a request to the API.

121
00:10:22,930 --> 00:10:29,110
In this case, we want to make requests through this request library from Python and then construct

122
00:10:29,110 --> 00:10:40,480
the URL you want to request or remove that part and the leaf only of double quotes followed by HTP as

123
00:10:40,480 --> 00:10:45,820
graph, etc. And it closes with a double quotes.

124
00:10:45,820 --> 00:10:47,360
So that's a Python string.

125
00:10:47,360 --> 00:10:47,590
No.

126
00:10:48,190 --> 00:10:58,900
And then we do respond to requests that get and we answer that you went in there and then we print out

127
00:10:59,020 --> 00:11:03,850
a response, the content and run.

128
00:11:07,150 --> 00:11:14,710
Request is going to be installed on my repo because it was not installed, and we should be seeing the

129
00:11:14,710 --> 00:11:15,940
results in just a bit.

130
00:11:22,780 --> 00:11:27,730
Yes, so that's the results is the same data that we got in here.

131
00:11:29,200 --> 00:11:33,900
Now just one thing you see this Barbie here, which means this is a big string.

132
00:11:34,720 --> 00:11:41,250
So if you want to get a plane stream, you want to say Texea instead of content, we're on again and

133
00:11:41,260 --> 00:11:44,710
then you should get a plane string, not be in front.

134
00:11:46,270 --> 00:11:54,370
So what's going on is well, and here you have this access token and this access token is fetched automatically

135
00:11:54,370 --> 00:12:02,080
by this interface in Python, though when you copy that's €c codes.

136
00:12:02,500 --> 00:12:05,740
What we copy is we also copy the access token.

137
00:12:05,980 --> 00:12:11,230
So you see this part of your access token is equal to the actual access token, which you find also

138
00:12:11,230 --> 00:12:11,710
in here.

139
00:12:12,220 --> 00:12:17,710
So that means access token now is included in here.

140
00:12:17,950 --> 00:12:19,150
That's my access token.

141
00:12:19,570 --> 00:12:24,630
And then we have this other ports onto here.

142
00:12:26,500 --> 00:12:30,790
So that's the base URL of the Graph API graph.

143
00:12:30,790 --> 00:12:34,930
That's Facebook dot com v thirteen point zero.

144
00:12:35,050 --> 00:12:38,320
And then we have this Port Me question mark.

145
00:12:38,890 --> 00:12:47,920
Fields is equal to D, and we have this percentage too, which means a empty space, a white space.

146
00:12:48,130 --> 00:12:50,050
And then we have a name.

147
00:12:50,830 --> 00:12:59,590
So that is the same as we see in here, more or less the same, although the commas are white spaces

148
00:12:59,590 --> 00:13:00,230
in here.

149
00:13:01,300 --> 00:13:03,070
So let me explain what this means.

150
00:13:03,400 --> 00:13:08,840
Well, MI is the equivalent of placing this idea.

151
00:13:08,980 --> 00:13:14,440
So this is your unique I.D. of of your Facebook user account.

152
00:13:14,950 --> 00:13:24,070
So even if I place that idea instead of me in here and I run, I will get the same results.

153
00:13:24,880 --> 00:13:32,140
So that's the standards, you know, and you can do the same in here, so you can place that idea instead

154
00:13:32,140 --> 00:13:32,620
of me.

155
00:13:33,310 --> 00:13:37,930
And then followed by question mark submits and you get the same results.

156
00:13:39,430 --> 00:13:45,730
So often have a question mark when we have the query, what fields do we need from this user account?

157
00:13:46,180 --> 00:13:48,520
Well, we need the I.D. and we need the name.

158
00:13:52,160 --> 00:14:00,230
And if we add posts, as I just did, it gives us also the information about posts.

159
00:14:01,870 --> 00:14:05,380
So let's see what we've got here.

160
00:14:06,670 --> 00:14:09,640
So we have Heidi, as the key of this dictionary.

161
00:14:09,760 --> 00:14:11,830
We have name as another key.

162
00:14:12,220 --> 00:14:14,230
So each key has its own value.

163
00:14:14,500 --> 00:14:24,520
Python Nesto is the value of name, and then we have the post's key supports has as a value of this

164
00:14:24,520 --> 00:14:25,340
dictionary.

165
00:14:26,440 --> 00:14:32,560
And so this is a dictionary which has another key Delta and Delta has as a value of this list of this

166
00:14:32,560 --> 00:14:33,100
list.

167
00:14:33,430 --> 00:14:34,060
The dictionaries.

168
00:14:34,270 --> 00:14:35,800
So this is one dictionary.

169
00:14:35,800 --> 00:14:38,020
It starts here, it ends in here.

170
00:14:38,470 --> 00:14:45,850
And this dictionary contains one posts, so it represents one Facebook post on my user account.

171
00:14:45,890 --> 00:14:47,200
Here I have two posts.

172
00:14:47,920 --> 00:14:52,420
This is this is my first post on Facebook and it says this comment.

173
00:14:52,940 --> 00:14:54,760
And that's another post.

174
00:14:55,030 --> 00:14:59,020
So two posts and here as well, we get these two posts.

175
00:14:59,110 --> 00:15:03,010
One here, you see, this is my second post.

176
00:15:04,180 --> 00:15:07,610
And then we have this other one in here.

177
00:15:07,660 --> 00:15:09,310
This is my first post.

178
00:15:10,510 --> 00:15:13,540
And then each post has a 90.

179
00:15:14,380 --> 00:15:15,670
Let me expand this a bit.

180
00:15:16,990 --> 00:15:18,670
So that's the idea of the post.

181
00:15:20,830 --> 00:15:24,040
Now you ask, what's all these other things?

182
00:15:25,090 --> 00:15:31,090
So we have two posts, then we have this other dictionary here.

183
00:15:31,120 --> 00:15:37,390
So one, two, three and four.

184
00:15:38,320 --> 00:15:40,880
What these are is photos.

185
00:15:40,900 --> 00:15:44,770
So I have four photos here on my Facebook profile.

186
00:15:45,820 --> 00:15:49,900
It's one to this is a Facebook main picture.

187
00:15:50,080 --> 00:15:53,410
So it's one two three four, actually without the tiger.

188
00:15:58,720 --> 00:16:04,540
And that's what we have in here now, let's repeat the same query in Python.

189
00:16:04,660 --> 00:16:05,470
So again, get.

190
00:16:05,830 --> 00:16:10,660
Go to €c and copy that entirely.

191
00:16:10,670 --> 00:16:14,860
Go to Python in the URL paste.

192
00:16:14,860 --> 00:16:15,990
That's clean it out.

193
00:16:18,770 --> 00:16:24,220
We run and we should get the same dictionary in here.

194
00:16:27,150 --> 00:16:31,470
So that's the dictionary is the same one with this in here.

195
00:16:32,280 --> 00:16:36,510
Next, how can we get one single posts?

196
00:16:37,170 --> 00:16:38,280
We have multiple polls.

197
00:16:38,610 --> 00:16:39,960
How can we get just one?

198
00:16:40,470 --> 00:16:42,420
Or how can we get to one single photo?

199
00:16:42,790 --> 00:16:43,560
Let me show you that.

200
00:16:44,430 --> 00:16:51,030
Now what you do is you need the I.D. of the posts that you want.

201
00:16:51,360 --> 00:16:57,360
So for example, this second post here we give the I.D. with place.

202
00:16:57,360 --> 00:16:59,430
It's in the beginning in here.

203
00:17:00,540 --> 00:17:02,820
So that is followed by a question mark.

204
00:17:03,450 --> 00:17:08,880
And then what fields do we need if we run this query as it is?

205
00:17:09,300 --> 00:17:14,010
We're going to get this error tried accessing not existing fields posts.

206
00:17:15,150 --> 00:17:24,300
Of course, it's not a field of one post, so ID name and posts were fields of the user accounts.

207
00:17:24,990 --> 00:17:29,310
So it gives us the idea of the user calling the name of the user account and the posts.

208
00:17:29,550 --> 00:17:35,550
So these are attributes of the user account, but these are not attributes or a pause.

209
00:17:35,580 --> 00:17:39,120
So for posts, you could have comments.

210
00:17:40,270 --> 00:17:42,420
Now this post the second post.

211
00:17:44,950 --> 00:17:48,310
Doesn't have any comments, so I'm going to add a comma now.

212
00:17:49,110 --> 00:17:59,170
Hey, this is a comment and then around this query again submits and then we have this common ski.

213
00:17:59,690 --> 00:18:03,310
And so this is the text of a comment.

214
00:18:04,600 --> 00:18:06,820
And the idea of a comment as well.

215
00:18:07,630 --> 00:18:09,580
So everything has an idea.

216
00:18:10,720 --> 00:18:16,660
And of course, you can do the same with this gets cold and put this in python to access it with requests.

217
00:18:17,830 --> 00:18:18,700
Photos No.

218
00:18:19,150 --> 00:18:21,580
Well, let's get to again me.

219
00:18:22,300 --> 00:18:30,340
So with me, you get the user I.D. And so if you add the slash and write posts and press, enter again,

220
00:18:30,430 --> 00:18:34,420
this is going to give you the posts and also the photos.

221
00:18:34,840 --> 00:18:38,500
So again, try to get the idea of one post in here.

222
00:18:39,250 --> 00:18:44,610
And of course, in Python, you can also iterate over these dictionaries and gets all the posts and

223
00:18:44,620 --> 00:18:49,870
then make another loop where you access each posts.

224
00:18:49,870 --> 00:18:54,070
You grab that idea and access it and then get the pictures.

225
00:18:54,580 --> 00:18:59,710
If you only want the photos, though, you can remove posts and write photos.

226
00:19:03,710 --> 00:19:09,770
But you also need to add slash uploaded to actually get the list of photos.

227
00:19:10,580 --> 00:19:15,320
So now we have the photos and we also have a description of the photos, if there is any.

228
00:19:15,890 --> 00:19:22,160
So when you upload the photo as a user on your Facebook account, it gives you the option to enter a

229
00:19:22,160 --> 00:19:22,830
description.

230
00:19:22,850 --> 00:19:24,890
So that's the description of the photo.

231
00:19:25,160 --> 00:19:26,480
And as the idea of the photo.

232
00:19:26,720 --> 00:19:30,140
So let's get this photo of this particular photo.

233
00:19:31,100 --> 00:19:40,760
You want a copy of that I.D. pasted directly in here and then add the question mark fields if you want

234
00:19:40,760 --> 00:19:41,640
to give any fields.

235
00:19:41,660 --> 00:19:43,190
Otherwise, just leave it like that.

236
00:19:43,820 --> 00:19:47,090
Submit that to give you vets.

237
00:19:47,390 --> 00:19:54,470
If you want to get the link of the photo again, you want to add the question mark fields a single to

238
00:19:54,980 --> 00:19:55,790
link.

239
00:19:56,900 --> 00:20:03,890
Press submits, and that should give you this link, if you could, that's going to take you to this

240
00:20:03,890 --> 00:20:04,610
page.

241
00:20:04,940 --> 00:20:06,890
You want to follow the coupe case.

242
00:20:15,990 --> 00:20:16,570
Try again yet.

243
00:20:16,860 --> 00:20:19,980
So that's the link of the photo.

244
00:20:20,670 --> 00:20:27,240
No, as you can see, this URL points to the photo page, not to the image file itself.

245
00:20:27,840 --> 00:20:32,190
So if you want the actual image, you want to do something else.

246
00:20:32,550 --> 00:20:38,900
So let's go back in here and sometimes you get this error of error validating access token.

247
00:20:38,910 --> 00:20:40,440
The session is invalid.

248
00:20:41,520 --> 00:20:45,900
That's happens because these tokens are only used for six minutes.

249
00:20:45,900 --> 00:20:48,210
They are valid for that six minutes.

250
00:20:48,210 --> 00:20:52,380
Then you want to press that button again to generate another access token.

251
00:20:54,540 --> 00:20:58,530
And then we want to run that square again, which was this.

252
00:21:01,060 --> 00:21:05,170
So in this new page with this new access token, submit.

253
00:21:06,940 --> 00:21:10,420
Oh, I forgot to enter the first number it's on.

254
00:21:11,050 --> 00:21:12,280
I missed one digit.

255
00:21:12,700 --> 00:21:17,960
So again, so that's the Facebook page of the image.

256
00:21:17,980 --> 00:21:21,250
Now if you had another here, common images.

257
00:21:22,210 --> 00:21:29,250
So you'll see that this interface can also suggest you fields images and presence of myths.

258
00:21:31,300 --> 00:21:33,880
Then you get this.

259
00:21:34,540 --> 00:21:36,820
So you have this link.

260
00:21:37,360 --> 00:21:41,920
Press it's a that's that points you to the actual image file.

261
00:21:46,470 --> 00:21:48,060
So there are two links, actually.

262
00:21:48,090 --> 00:21:51,900
One, you have this big image and want a smaller image.

263
00:21:55,470 --> 00:21:59,970
So with five and then you can choose to download whichever you want.

264
00:22:00,540 --> 00:22:09,000
So next, let's try to download this first image and see if it's an actual image file in Python.

265
00:22:11,070 --> 00:22:13,050
So first of all, we need to get the codes.

266
00:22:15,040 --> 00:22:15,580
Cockpit.

267
00:22:18,110 --> 00:22:22,160
Place, it's in the other variable clean that's.

268
00:22:24,590 --> 00:22:25,490
So that's zero.

269
00:22:26,390 --> 00:22:29,930
This should give us that same dictionary.

270
00:22:30,590 --> 00:22:34,280
So now we want to access a let's go again in here.

271
00:22:34,560 --> 00:22:37,160
Not this one, this one.

272
00:22:37,460 --> 00:22:46,760
So I want to look at here because we have a cleaner view of this dictionary, so we want to access the

273
00:22:46,760 --> 00:22:48,050
images key.

274
00:22:49,340 --> 00:22:50,090
Let's do that.

275
00:22:52,040 --> 00:23:03,260
So data is equal to Respawn's the text and if we print just data images.

276
00:23:07,790 --> 00:23:15,710
We get this error because Delta is actually a strength at this point.

277
00:23:17,490 --> 00:23:22,620
So it's a strength, even though it looks like a dictionary, that dictionary is wrapped inside a string.

278
00:23:22,830 --> 00:23:29,540
So we want to convert that string into an actual Python Dictionary object for that.

279
00:23:29,540 --> 00:23:35,880
So we need to import Jason than that.

280
00:23:35,970 --> 00:23:39,780
So it would be equal to JSON that loads.

281
00:23:40,590 --> 00:23:42,090
And then we enter Delta.

282
00:23:43,290 --> 00:23:49,800
So Delta currently is a string so that Delta is a string, but it will be converted into a dictionary.

283
00:23:50,160 --> 00:23:51,510
So if I print it all now.

284
00:23:52,230 --> 00:23:57,780
Now we have a DICT, so let's bring out the delta.

285
00:23:57,790 --> 00:24:05,790
It looks the same as you will see is still the same, but now we can access the keys of the dictionary

286
00:24:06,330 --> 00:24:09,900
because Python now knows how to pass that object.

287
00:24:11,250 --> 00:24:17,070
So that's who gave us this list, which is basically, yeah, this one here.

288
00:24:18,180 --> 00:24:18,900
That's a list.

289
00:24:19,270 --> 00:24:22,950
Now let's get the first item of that list, which is this first dictionary.

290
00:24:23,040 --> 00:24:27,870
So the list has to dictionaries this one, and that's another one.

291
00:24:28,830 --> 00:24:33,270
So by applying an index of zero.

292
00:24:35,900 --> 00:24:38,430
We get that first dictionary rights.

293
00:24:39,230 --> 00:24:43,580
And then out of the dictionary, so we get this one.

294
00:24:43,730 --> 00:24:50,540
And then out of that, we get the source key, the value of the source key.

295
00:24:52,780 --> 00:24:53,530
Soldiers.

296
00:24:57,060 --> 00:25:01,710
So that gives us the URL, which if you click it, it takes you to that image.

297
00:25:02,010 --> 00:25:03,830
No, next.

298
00:25:04,200 --> 00:25:07,830
Let's save this URL to an image.

299
00:25:07,860 --> 00:25:08,850
You are a variable.

300
00:25:10,170 --> 00:25:13,680
Remove the parentheses of the print function.

301
00:25:15,300 --> 00:25:22,590
And then what we want to get now is to get the contents of that image, the Boyds.

302
00:25:23,190 --> 00:25:24,870
And we do that.

303
00:25:27,500 --> 00:25:37,610
With requests to gets again, and this request gets now, gets zero of the image images were so previously

304
00:25:37,610 --> 00:25:45,920
it got it got the usual or that a web page and now it's a you or a loved one image and we extract the

305
00:25:45,920 --> 00:25:46,670
content.

306
00:25:48,230 --> 00:25:50,990
So now we want the content, not texts.

307
00:25:51,000 --> 00:25:52,760
So we were working with bytes.

308
00:25:53,270 --> 00:25:57,530
Images are binary, files are not, they are not text files.

309
00:25:58,490 --> 00:26:10,030
And then we open a file locally with open image the chief p g in right binary mode as file and in that's

310
00:26:10,040 --> 00:26:11,090
new file object.

311
00:26:11,090 --> 00:26:11,720
We were right.

312
00:26:12,110 --> 00:26:22,100
Image voids that variable and we run the script adds an image.

313
00:26:22,100 --> 00:26:25,130
The JPG chief file is downloaded.

314
00:26:25,310 --> 00:26:28,070
We click it and we see the actual cat image.

315
00:26:29,660 --> 00:26:35,810
So that's how we can get an actual photo from Facebook via Python.

316
00:26:36,530 --> 00:26:47,060
And lastly, if you want to see the documentation, you want to go to docs and just over the mouse there

317
00:26:47,060 --> 00:26:49,460
and then go down to Graph API a reference.

318
00:26:52,950 --> 00:26:56,500
And even here in this listing here.

319
00:27:00,450 --> 00:27:03,960
You'll see all the notes that you can get.

320
00:27:04,380 --> 00:27:07,920
So, for example, we worked with photos.

321
00:27:08,000 --> 00:27:09,540
So I'm going to search for photos.

322
00:27:11,880 --> 00:27:12,960
It's a long document.

323
00:27:14,710 --> 00:27:16,420
So photo is something that we got.

324
00:27:16,470 --> 00:27:22,050
If you click that, it'll take you in here.

325
00:27:22,320 --> 00:27:29,880
So if you scroll down, for example, you see a table of fields that you can pass to photos.

326
00:27:32,470 --> 00:27:41,590
So in this example, here we pass the link field for photos, but you can pass all the fields as you

327
00:27:41,590 --> 00:27:43,540
see in this table.

328
00:27:47,240 --> 00:27:50,640
So with that, I wanted to finish this video.

329
00:27:50,660 --> 00:27:55,760
There's more and more about the Facebook API, and of course, I cannot cover it.

330
00:27:55,760 --> 00:28:03,280
All of the points of visibility was to give you some orientation on how to start to get started with

331
00:28:03,290 --> 00:28:04,700
a Facebook API.

332
00:28:05,540 --> 00:28:12,830
The things you can do with the Facebook API are infinite, so I hope this helps you to get some ideas.

333
00:28:12,830 --> 00:28:17,120
And whenever you need the Facebook API, just click this video to get started.

334
00:28:17,540 --> 00:28:18,000
Thank you.

335
00:28:18,180 --> 00:28:18,350
You.

