Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

Authentication

Ander Goig edited this page Jan 21, 2018 · 15 revisions

In order to authenticate Instagram users you have two options ✌️

You can use the included authentication method in SwiftInstagram, which will handle the authentication process for you. Or use your own one and let SwiftInstagram know the access token.

SwiftInstagram authentication

SwiftInstagram uses client side (implicit) authentication, so you must uncheck the option "Disable implicit OAuth" from the Security tab of your Instagram client.

Copy the Client ID from your client and paste it inside your Info.plist file with InstagramClientId as the key. Do the same with your redirection URI and the InstagramRedirectURI key.

Info.plist

let api = Instagram.shared

// Login
api.login(from: navigationController!, success: {
    // Do your stuff here ...
}, failure: { error in
    print(error.localizedDescription)
})

// Returns whether a user is currently authenticated or not
let _ = api.isAuthenticated

// Logout
api.logout()

You can also specify the login permissions with the optional withScopes parameter. By default, it is set to .basic access only, however, you can request multiple scopes at once:

api.login(from: ..., withScopes: [.likes, .comments, .followerList], ... )

Your own way

As I said, is not mandatory to use the previous method. If you already own an access token you could just use the following:

Instagram.shared.storeAccessToken(<YOUR ACCESS TOKEN>)

Next

Let's go! 😎 Now you can start requesting some data from Instagram.