Hi Alex here from rebeloper.com and welcome back to the Christmas Calendar tutorial series!
And in this one I will show you how you can use the Instagram API API in Swift
Let's get started!
Great! Now why would you use the Instagram API?
As you already know it has been a limited quite a lot and we don't have
that flexibility but there is still a use case or maybe more use cases for the
Instagram API. Let me just show you what is bothering me. I'm using my
phone here and let's go into Instagram and let's see I do have my post count I
do have my following count precisely. But my followers and that is what I'm really
interested in that is 11.5 K. I don't really know the exact number and I
really want to know that because I'm a man of numbers. Furthermore what bothers
me is here you need to go into the let's say tab on the first image and then you
can see how many likes and comments did I get. But as usual I like to have this
information as soon as possible. So we are going to create with the Instagram
API an InstantGraham so called InstantGraham app that will show the
followers number exactly and our likes and comments number. And let me show you
what we are going to build out again. This is on the right side of the screen
and that is it. We can show the likes as you can see it's
804 and let me just go in yes there it is 804. And let me switch to the comments
five comments that is correct. And again and let me just go back here. And here it
says on my device 11.5 K and here is the exact number of how many
followers I have. Okay, of course I can scroll down this API seems to be
limiting the fetching of the post to twenty but that is okay. And as you can
see I also have the post numbers following numbers and my profile picture
the full and name because this is your full name added here and my bio and the
link. Exactly the same as it is on my device. Now we can go back to showing
likes and we can also refresh this, if we wanted to. And also I have added here an
extra thing how many posts did I post since the last entry in this app. And how
many followers did I gain or lose and how many did I follow or unfollow.
This could be a negative number we will see that when we get to the code. That is
really interesting that basically isn't in the actual Instagram app. Now we are
going to build this out so let's get started! In this first video I am going
to show you how you can set up the Swift Instagram API. Okay, now let me just
minimize these well maybe I'll not have the simulator and let's open up our
browser. And just a quick shout out now this Swift Instagram let's say a library
that I have created is due to undergoing and it this repository has been arrived
by this owner so I just copied it and modified it a little bit and you can
simply go and check in the description and click the link there and you will be
taken to where you can download all of the resources for my YouTube tutorials.
Go ahead and download the resources and you will be presented with these...
Let me just go tear Swift Instagram API resources and here it is how to...
Let me make this a little larger so I may read because it's a large nam: How to create
InstagramClientid and InstagramRedirectURI and that is what we are
going to do today. And of course you have the Swift Instagram folder with all
of the codes. Of course again this is under goings work a little bit
tweaked by me. Let's go back and open up at this file and see what we need to
do in order to have these two Instagram client ID and Instagram redirect URI.
Before we do that go ahead and also in the site where you can find
these resources you have the link to my GitHub repository and that will take you
to the repository go ahead and download it unzip it or clone it. And once you do
that you will see that you don't have this Xcode workspace but you do have
your Podfile. Now what you want to do is open up terminal. Okay and type in CD and
the space and simply drag and drop the root folder of your project. Now hit
return and... oh you already will have the necessary pods added to your podfile so
all you need to type in is: pod install. Okay, hit return
and all of these extra files will be created including the Xcode workspace.
Now, that we have that out of the way
go ahead and open up your Xcode workspace and you will be presented with this.
If you wish you could build and run and test it out but no need for that.
Now where are all of these two keys? Well they are in the info.plist file. Here it
is Instagram client ID and where is the other one... Instagram redirect URI.
Now we are going to do create those two now. Go back to this file and select Manage Clients.
That is a link and that will take you to instagram.com/developer/clientsmanage
Okay, if you are not already signing then do so.
Well you could go to developer and then sign in and then click on this
manage clients button. Now the next thing you want to do is click register a new client.
Well I already have that and I already have my client ID and so on.
But what you need to do next is fill up your app data and I won't do this again
because it's sensitive data and it is straightforward what you need to do.
Again just a second here you will have... let me click on here manage and security...
there will be a valid red direct URI and go ahead and hit return or enter for that.
Okay, let me just cancel out of this that will be pretty straightforward
to fill out your app data. Click register then go back again here and you will be
presented with this. You will see your client id
you are looking for. Here is my client ID and let me copy that out and paste it
in the Instagram client ID a value field. There we go!
All we need is our Instagram Redirect URI. Now this is a bit tricky so
we need to click on the manage. Let's do that now. Click on manage and then
click on security. And this will be empty. Okay! So under valid valid redirect URI's
you will not have anything. Now in this link it according to subdan and
go ahead and check out his repository too. He says that you need to specify a valid
redirect URI or just one. He set it to this one and it should not be a
real URL. I don't really know about this sometimes it is okay to add in a
dummy URL sometimes it isn't. Go ahead and test it out for your own domain. Okay!
Now once you do that go ahead and copy it out. Let's hit command C and paste it
under Instagram redirect URI in your Xcode. That's that and of course don't
forget to scroll down and yes before we update the client disable implicit OAuth.
And I believe this would be register or something like that. Make sure a
disable implicit OAuth is unchecked. I will just update client that's okay and
that is it. We are ready! Okay that's it for getting our Instagram client ID and
Instagram redirect URI. Okay, now one last thing that we are going to add in this
video is simply to drag and drop our swift Instagram
folder. Let me just drag and drop it right there. Make sure copy items if
needed is checked, create groups is checked and also the target is checked.
Click on Finish and let me just take a short tour of this library. Okay, here
we have our Instagram and our InstagramScope. And here we have our Endpoints.
One thing to note about Endpoints a lot of them have been deprecated by Instagram.
So some of these will work some of these will not maybe in the future none of
them will work. But go ahead and take a look at the models here. And we are going
to heavily use this InstagramUser and the InstagramMedia. And I believe that
is it we still have some location and tags and comments and so on. You can
fetch that once we get down into the code you will know how. Now let me just
talk a little bit and we will finish off this tutorial out by taking a look at the
structure of this starter project. Well we have our app delegate and of course
because we have already removed the main.storyboard and the reference to it
in the info.plist file we have our profile view controller. And we added it
into the navigation controller and we are making it for the root view
controller of our window. Now let me just say because we are going to go deeper
into the code in the next video we have here a collection view. If we
are not authenticated then we show in front of that profile view controller...
and that is a collection... view we show an auth view controller where we can
log in. Now this collection view controller that is just the basic class
from UI view controller that basically profile view controller inherits from
this collection new controller. We have a
profile header file. Let me just go all the way up and an image cell for the posts.
Okay, what do we have? we have our app icon and lastly. Okay, now that is it for
this video I hope you enjoyed it. If you did go ahead and give it a thumbs up
subscribe to the channel and I dare you to hit that notification bell. Now it is
your turn go ahead and comment down below what is your opinion: Does the
Instagram API... is it still use in use or is it
useless? What do you think do you have any ideas of how we could use it besides
mine that I will show you in the next video? Go ahead and comment down below
and really interested in your ideas and in your opinion. Now that is it for me
today and I will see you in the next one!