1
00:00:07,820 --> 00:00:12,820
Hey guys this is Kayla with slopes and in this video we're going to access the flicker API.

2
00:00:12,920 --> 00:00:15,280
That's what we're going to use to download photos by the way.

3
00:00:15,280 --> 00:00:18,770
If you didn't know already you probably did because I've said it like 100 times.

4
00:00:18,770 --> 00:00:21,340
Anyway we're going to access the Flickr API.

5
00:00:21,470 --> 00:00:25,780
We're going to get ourselves an API key and then I'm going to show you how the Flickr API is you are

6
00:00:25,780 --> 00:00:30,910
l scheme works so that you know how you can download photos exactly the way you want to.

7
00:00:31,090 --> 00:00:36,440
So go ahead and pull open your Safari browser and we're actually going to go ahead and go to Flickr

8
00:00:36,440 --> 00:00:40,170
dot com slash services slash developer.

9
00:00:40,220 --> 00:00:42,460
And this is the Flickr developer guide.

10
00:00:42,470 --> 00:00:43,910
There's all kinds of information.

11
00:00:43,910 --> 00:00:47,090
They have a pretty good community business.

12
00:00:47,240 --> 00:00:49,050
They have all this stuff.

13
00:00:49,100 --> 00:00:53,300
The only thing you need to know is that actually you need to log into a Yahoo account because Flickr

14
00:00:53,300 --> 00:00:55,040
is owned by Yahoo.

15
00:00:55,040 --> 00:01:00,400
So once you log into your Yahoo account you can go here and click on API.

16
00:01:00,410 --> 00:01:05,070
Once that load you can click on request an API key K..

17
00:01:05,670 --> 00:01:07,910
And we're gonna go to get your API.

18
00:01:07,980 --> 00:01:09,620
The number one option.

19
00:01:09,690 --> 00:01:11,160
Now there are two options here.

20
00:01:11,170 --> 00:01:14,790
Commercial commercial or noncommercial.

21
00:01:14,790 --> 00:01:17,810
Now that's for us our app does not make money.

22
00:01:17,850 --> 00:01:22,200
You could also use this though if your app does make money but you're a family run smaller independent

23
00:01:22,200 --> 00:01:22,910
business.

24
00:01:23,100 --> 00:01:27,600
You're developing a product which is not currently commercial but might be in the future or you're building

25
00:01:27,600 --> 00:01:31,930
a personal web site or blog where you're only using your own images but our app doesn't make money.

26
00:01:31,950 --> 00:01:32,700
That's us.

27
00:01:32,700 --> 00:01:35,770
So let's apply for a noncommercial key.

28
00:01:35,820 --> 00:01:36,050
OK.

29
00:01:36,050 --> 00:01:38,910
Now of course this shows you're the owner of the account.

30
00:01:39,150 --> 00:01:47,130
The name of our app is pixel city and we're building an app that downloads photos from the internet

31
00:01:47,790 --> 00:01:52,220
and displays them for a location.

32
00:01:52,650 --> 00:01:55,410
Pretty simple little description.

33
00:01:56,060 --> 00:01:57,890
And let's go ahead and let's check this.

34
00:01:57,890 --> 00:02:02,850
I acknowledge that flicker members own all rights to their content and it's my responsibility to make

35
00:02:02,850 --> 00:02:06,330
sure that my project does not contravene those rights.

36
00:02:06,390 --> 00:02:10,680
That's where that's what we're doing we're not using the photos for anything other than displaying them.

37
00:02:10,680 --> 00:02:15,950
And we also agreed to comply with the flicker terms of use press submit.

38
00:02:16,130 --> 00:02:22,970
And as soon as it loads boom there's our API key there is our secret and all we're going to actually

39
00:02:22,970 --> 00:02:25,400
mean is the API key.

40
00:02:25,460 --> 00:02:32,660
So we are now at a point where we can create a Constans file on our project and we can use that to basically

41
00:02:32,660 --> 00:02:34,670
store our API key for use.

42
00:02:34,670 --> 00:02:38,310
So let's go ahead and pull open our tax code project really quickly.

43
00:02:38,450 --> 00:02:41,930
We'll go back to the API and we'll look at how you work in just a second.

44
00:02:42,050 --> 00:02:48,680
But for now we're going to go into the utilities folder and create a new file click swift file and we're

45
00:02:48,680 --> 00:02:55,130
going to call this Constance and these are going to be used for things that maybe we use a lot and you

46
00:02:55,130 --> 00:03:00,020
know when we go back we can actually use this photocell identifier as a constant.

47
00:03:00,050 --> 00:03:03,190
We use it more than one time drop a pin.

48
00:03:03,230 --> 00:03:04,480
We use that more than one time.

49
00:03:04,490 --> 00:03:09,870
We can create a constant that basically makes our app a little less strongly.

50
00:03:10,040 --> 00:03:15,380
When you retyped strings that can cause problems if you mistype it here or mis type it here it's better

51
00:03:15,380 --> 00:03:20,060
to create one constant variable and then call that variable because you can't mistype the variable things

52
00:03:20,130 --> 00:03:22,540
to auto complete.

53
00:03:22,580 --> 00:03:24,970
But anyway let's go create one for our API.

54
00:03:25,350 --> 00:03:26,180
So in here.

55
00:03:26,180 --> 00:03:29,260
Go ahead and just type let API key.

56
00:03:29,750 --> 00:03:34,750
And of course we're going to need to paste it from here so select your API key.

57
00:03:34,910 --> 00:03:36,680
Copy it and paste it.

58
00:03:36,920 --> 00:03:37,640
And that's that.

59
00:03:37,670 --> 00:03:38,780
There's your API.

60
00:03:39,020 --> 00:03:39,900
Awesome.

61
00:03:39,950 --> 00:03:45,950
So that's saved in our app Let's go ahead and head back to flicker and we're going to go to what's called

62
00:03:45,950 --> 00:03:52,280
the flicker API Explorer which you can access by going to this very long you l flicker dot com slash

63
00:03:52,280 --> 00:03:59,780
services slash API slash explore slash flicker dot photos that search flicker stuff Flickr photos that

64
00:03:59,780 --> 00:04:03,780
search is actually the part of the API that we're going to use.

65
00:04:03,830 --> 00:04:12,590
The reason for that being is that you can pass in a latitude and longitude and a radius and it will

66
00:04:12,590 --> 00:04:18,460
allow you to find all photos within that latitudinal radius really really cool.

67
00:04:18,470 --> 00:04:27,290
Now the API Explorer here allows you to choose which parts of the potential options you want to add

68
00:04:27,290 --> 00:04:29,410
in the API call which is very cool.

69
00:04:29,410 --> 00:04:32,230
You can see there's a lot of different options here.

70
00:04:32,540 --> 00:04:35,330
You can sort photos by the minimum upload date.

71
00:04:35,330 --> 00:04:37,880
Maybe you only want photos that are from this month.

72
00:04:37,910 --> 00:04:41,020
Or you can sort them by content type.

73
00:04:41,030 --> 00:04:42,530
Maybe you actually only want video.

74
00:04:42,530 --> 00:04:43,790
You can download those too.

75
00:04:44,150 --> 00:04:51,320
But for us we just want a Latitude Longitude a radius and we have to give the radius in a certain unit.

76
00:04:51,350 --> 00:04:58,460
So for example I'm just going to put in random coordinates here maybe 40 2.8 by one hundred twenty two

77
00:04:58,460 --> 00:05:03,570
point three and the radius we're going to make it a one mile radius.

78
00:05:03,750 --> 00:05:05,350
Whoops a one mile radius.

79
00:05:05,360 --> 00:05:08,810
And let's just say that the unit will be Miles am I.

80
00:05:09,070 --> 00:05:13,420
If you want to use kilometers you can K.M. meters just an it's up to you.

81
00:05:13,420 --> 00:05:16,310
You can set it up to be whatever radius you want.

82
00:05:16,310 --> 00:05:18,370
That's the cool thing about the API.

83
00:05:18,440 --> 00:05:23,200
So we have now given it all of the properties we want and we want to see the output.

84
00:05:23,210 --> 00:05:25,880
Now in this app we're going to be working with Jason.

85
00:05:25,940 --> 00:05:33,890
That's just really easy to use with with iOS and so with Jaison we can get that output.

86
00:05:33,890 --> 00:05:37,590
Now something that you can see here that's very very cool.

87
00:05:37,640 --> 00:05:43,670
We can call this API we can make a call and download all the Jaison without even needing to sign it

88
00:05:43,670 --> 00:05:49,720
with my permissions or a user token or anything we can we can send it as anybody which is cool.

89
00:05:49,730 --> 00:05:53,230
So click do not sign call and then click call method.

90
00:05:54,730 --> 00:05:57,520
Now if we scroll down we'll see what happened.

91
00:05:57,670 --> 00:06:04,540
Looks like it's loading and it froze we're making too many API calls at once.

92
00:06:04,540 --> 00:06:05,770
No that's not true.

93
00:06:05,800 --> 00:06:07,630
I'm actually not sure why it's not loading.

94
00:06:07,630 --> 00:06:11,080
Let's go ahead and try reloading this bad boy.

95
00:06:15,630 --> 00:06:16,030
OK.

96
00:06:16,050 --> 00:06:17,630
Really just not like me.

97
00:06:17,670 --> 00:06:18,590
This is weird.

98
00:06:24,520 --> 00:06:31,720
Cathro one more time just try reloading it and it's just going to keep getting stuck right.

99
00:06:31,720 --> 00:06:36,500
Looks like I'm bringing in the big dogs and bringing in Chrome let's copy this URL.

100
00:06:36,760 --> 00:06:39,910
Let's throw it in Chrome here and let's try it again.

101
00:06:39,910 --> 00:06:43,010
Sometimes when Safari does not work I pick brick.

102
00:06:43,020 --> 00:06:44,720
I have to go to Chrome.

103
00:06:44,770 --> 00:06:45,310
So sad.

104
00:06:45,340 --> 00:06:45,660
OK.

105
00:06:45,670 --> 00:06:46,690
Let's try it again.

106
00:06:46,700 --> 00:06:50,630
Latitude forty two point eight I think 122.

107
00:06:51,010 --> 00:06:56,330
We want that that one twenty two point eight The radius is one.

108
00:06:56,430 --> 00:06:58,350
The unit is Miles.

109
00:06:58,360 --> 00:07:02,400
We want this to output in Jaison and we're not going to sign the call.

110
00:07:02,440 --> 00:07:09,340
Go ahead and click call method and when you scroll down you'll see right here that you get a call.

111
00:07:09,340 --> 00:07:12,860
Now of course the photo data is obscured for the moment.

112
00:07:12,940 --> 00:07:18,670
But when you actually call this in your app all of the photo information will be inside of this dictionary

113
00:07:18,730 --> 00:07:20,060
which is very cool.

114
00:07:20,170 --> 00:07:21,790
So you can see that this is working.

115
00:07:21,790 --> 00:07:24,350
We get a lot of photos.

116
00:07:24,430 --> 00:07:27,390
We get all kinds of information.

117
00:07:27,490 --> 00:07:28,280
And you know what.

118
00:07:28,450 --> 00:07:33,510
The interesting thing is I actually want to set a certain number of results.

119
00:07:33,550 --> 00:07:38,160
So there is another one here that allows us to set the number of results that we get.

120
00:07:38,230 --> 00:07:43,080
And let's say per page let's say per page we want to download 40 photos.

121
00:07:43,090 --> 00:07:48,040
So if I call that method you'll see we get a successful return and look at this.

122
00:07:48,040 --> 00:07:50,960
We get a U R L we can see how it works.

123
00:07:51,070 --> 00:07:55,280
To see this better I'm actually going to copy it and I'm going to paste it into X code.

124
00:07:55,690 --> 00:08:00,220
So I'm just going to paste it here so we can take a look at what we're what we're dealing with here.

125
00:08:00,250 --> 00:08:07,300
So API flicker dot com slash services slash rest and the method here is flickery photos like that search.

126
00:08:07,300 --> 00:08:11,470
Like I said our API key is here but does that match.

127
00:08:11,470 --> 00:08:12,040
No it doesn't.

128
00:08:12,040 --> 00:08:14,680
So that's just a generic API that they're showing.

129
00:08:14,680 --> 00:08:16,420
We'll fix that in just a second.

130
00:08:16,480 --> 00:08:20,340
Now the Latitude has passed in the longitude the radius is one.

131
00:08:20,410 --> 00:08:27,340
The unit is miles per page we return 40 items and the format is Jaison.

132
00:08:27,460 --> 00:08:34,360
OK don't worry about no Jason callback but this is a u r l that we are going to use to download all

133
00:08:34,360 --> 00:08:39,910
the photos that we want but we need to write a function that allows us to pass in the relevant data

134
00:08:39,940 --> 00:08:45,760
like our API key the latitude and longitude the number of items that we want returned.

135
00:08:45,790 --> 00:08:52,030
So let's do that now let's go ahead and write a function called phunk flicker you RL and I'm doing this

136
00:08:52,030 --> 00:08:58,450
in my Constans file because I want to be able to access this anywhere and Constans file allows me to

137
00:08:58,450 --> 00:08:59,220
do that.

138
00:08:59,230 --> 00:09:02,430
So we're going to pass in a couple things into this function.

139
00:09:02,680 --> 00:09:05,430
OK let's go in brackets so it stops yelling at us.

140
00:09:05,680 --> 00:09:08,160
We need to pass in our API key.

141
00:09:08,290 --> 00:09:10,850
We need to pass in an annotation.

142
00:09:10,900 --> 00:09:13,860
And that's the same same as the pin that gets dropped.

143
00:09:13,860 --> 00:09:18,280
We're going to pass in that annotation and pull out the latitude and longitude.

144
00:09:18,310 --> 00:09:21,800
We're also going to pass in a number of photos.

145
00:09:21,850 --> 00:09:22,390
OK.

146
00:09:22,660 --> 00:09:28,560
So we're going to say flicker yourself for API key and we're going to just create an internal parameter

147
00:09:28,560 --> 00:09:31,320
here called Key of type String.

148
00:09:31,420 --> 00:09:35,890
We're going to say with annotation with an internal parameter of annotation.

149
00:09:36,100 --> 00:09:39,390
Now we already have a custom subclass called drop a pen.

150
00:09:39,430 --> 00:09:47,200
We'll use that and number of photos for a number.

151
00:09:47,260 --> 00:09:49,190
And that's going to be of type int.

152
00:09:49,210 --> 00:09:56,350
Now at the end of this we want this to return to us a string of our finished and perfected you r l.

153
00:09:56,350 --> 00:10:02,740
So in order to return that we're going to actually just use return and now we can pass in this you are

154
00:10:02,740 --> 00:10:03,830
l.

155
00:10:03,910 --> 00:10:07,630
So go ahead and cut this u r l and we're going to modify it to fit our needs.

156
00:10:07,810 --> 00:10:12,220
So return a string with this you r l.

157
00:10:12,250 --> 00:10:13,630
Now all of this is good.

158
00:10:13,810 --> 00:10:17,140
Let's go ahead and minimize this we can see more of it.

159
00:10:17,260 --> 00:10:20,200
This is good right API to flicker services rest.

160
00:10:20,200 --> 00:10:21,100
Flickr photo search.

161
00:10:21,100 --> 00:10:27,400
Nothing changes but the first thing that changes is the API key we can pass that in using string encapsulation.

162
00:10:27,400 --> 00:10:31,510
So let's go ahead and use our little special string syntax here.

163
00:10:31,750 --> 00:10:38,050
And I know it's hard to see because of the length of the string but we're going to pass in API key and

164
00:10:38,050 --> 00:10:39,730
where the old key was.

165
00:10:39,730 --> 00:10:43,750
Now we're passing in our own key now for the latitude.

166
00:10:43,750 --> 00:10:45,040
We can do the same thing.

167
00:10:45,330 --> 00:10:45,930
OK.

168
00:10:46,090 --> 00:10:55,280
We can pass in the annotation and then we can get the coordinate and we can pull out the latitude.

169
00:10:55,330 --> 00:10:56,430
Same with the longitude.

170
00:10:56,430 --> 00:11:04,050
We can do the same thing inside of those parentheses we can go to the annotation coordinate that longitude

171
00:11:04,050 --> 00:11:05,440
and we can pull that out.

172
00:11:05,440 --> 00:11:07,660
Now the radius the unit that never changes.

173
00:11:07,660 --> 00:11:10,780
But what if we want to change the number of results we get.

174
00:11:10,780 --> 00:11:16,630
So we're going to pass in using our concatenation we're going to pass in our sorry concatenation.

175
00:11:16,630 --> 00:11:21,040
The encapsulation we're going to pass in the number of results that we want.

176
00:11:21,280 --> 00:11:26,720
So now when we call this function it's going to return to us a perfect U r l.

177
00:11:26,920 --> 00:11:32,310
Now I'm actually going to go ahead and I'm going to make this a constant for now.

178
00:11:33,160 --> 00:11:41,230
And I want to print it first just so we can see that it works print u r l and then return you r l k.

179
00:11:41,230 --> 00:11:46,930
Let's go ahead and let's find a space to call this and see how we do.

180
00:11:46,930 --> 00:11:53,190
Let's see if we can get a nice nice fancy u r l I think a good place to call it would be here.

181
00:11:53,350 --> 00:11:57,730
Now let's go ahead and call that WIPs.

182
00:11:58,390 --> 00:12:01,620
We're going to print it because it returns a string to us.

183
00:12:01,780 --> 00:12:07,990
And let's go ahead and try it now let's build and run a whoops of course we forgot to call all of our

184
00:12:07,990 --> 00:12:08,860
fancy stuff.

185
00:12:08,870 --> 00:12:09,870
What's wrong with us.

186
00:12:10,100 --> 00:12:17,080
OK so we are going to go ahead and pass in the API key from our Constans file our annotation.

187
00:12:17,070 --> 00:12:17,980
We do not yet have.

188
00:12:17,980 --> 00:12:27,090
So let's actually move this down below because then we have our annotation pass in the annotation then

189
00:12:27,100 --> 00:12:31,100
number of photos let's say 40.

190
00:12:31,120 --> 00:12:33,310
So let's go ahead and build and run.

191
00:12:33,490 --> 00:12:40,600
When we tap to drop a pin the screen should slide up and we should see this print out a nice u r l and

192
00:12:40,600 --> 00:12:46,050
we can actually go ahead and check it to see if it properly is pulling from flicker.

193
00:12:46,570 --> 00:12:49,260
So pull open the simulator.

194
00:12:49,670 --> 00:12:50,590
There we go.

195
00:12:50,860 --> 00:12:54,200
Let's drop a pin and let's see what prints out.

196
00:12:54,220 --> 00:12:55,060
All right look at that.

197
00:12:55,060 --> 00:12:56,460
Very cool.

198
00:12:56,570 --> 00:12:57,910
So yeah.

199
00:12:57,940 --> 00:13:04,420
Looks like it's working there's a nice you Arel let's copy it and paste it over to Chrome and let's

200
00:13:04,420 --> 00:13:05,370
look at it.

201
00:13:05,860 --> 00:13:07,530
Yeah we have our API.

202
00:13:07,570 --> 00:13:08,480
That's ours.

203
00:13:08,530 --> 00:13:14,310
That is the latitude that is the longitude and 40 results when we call it.

204
00:13:14,320 --> 00:13:22,410
Look at that we get an array of all the photos all the data from that exact GPS GPS coordinate.

205
00:13:22,480 --> 00:13:28,750
So so cool we're going to dive into this in much greater detail in the next video and we're going to

206
00:13:28,750 --> 00:13:34,090
actually start retrieving the you or else for each image and then downloading the images using Alamo

207
00:13:34,090 --> 00:13:35,170
fire image.

208
00:13:35,170 --> 00:13:37,630
Very very awesome work guys.

209
00:13:37,990 --> 00:13:38,430
So yeah.

210
00:13:38,440 --> 00:13:44,320
Get ready for the next video you can of course delete this print function and we can of course fix this

211
00:13:44,320 --> 00:13:49,600
back to where it was before we were printing out and it's going to undo that we're just returning that

212
00:13:49,600 --> 00:13:50,950
value and.

213
00:13:50,980 --> 00:13:54,240
Yeah let's move on to the next video let's start downloading some images.

214
00:13:54,280 --> 00:13:55,570
I'll see in the next video.

