Reputation: 107
I have been trying to create an iOS app with SimpleAuth to authenticate Instagram.
In my AppDelegate.swift I have:
SimpleAuth.configuration()["instagram"] = ["client_id": "MY-CLIENT-ID", SimpleAuthRedirectURIKey: "MY-REDIRECT-URL"]
(Obviously inserting the client ID and redirect URI where needed)
And in my ViewController.swift I have:
@IBAction func instagramAuthenticate(sender: AnyObject) {
SimpleAuth.authorize("instagram", options: ["scope" : ["likes"]], completion: {
(responseObject : AnyObject!, error : NSError!) -> Void in
println("\(responseObject)")
})
}
For some reason when the user authorizes my app, the responseObject appears to return 'nil'. Possible meaning something went wrong.
I am relatively new to Swift/iOS and am not sure what I have done incorrectly. Thanks
Upvotes: 1
Views: 349
Reputation: 107
Turned out my redirect URI was the reason it was returning nil. I changed it and everything worked perfectly! Thanks to HorseT in the comments above.
Edit: More in-depth answer below
All the following information can be found here.
Firstly, you must configure Instagram in your AppDelegate.swift
//Instagram Confifuration
SimpleAuth.configuration()["instagram"] = ["client_id": "YOUR-CLIENT-ID", SimpleAuthRedirectURIKey: "myApp://Auth/instagram"]
Make sure the SimpleAuthRedirectURIKey
is equal to that in your app settings on the instagram developers page.
Next you need to authorize the user.
SimpleAuth.authorize("instagram", options: ["scope" : ["basic", "comments", "likes", "relationships"]], completion: {
(responseObject : AnyObject!, error : NSError!) -> Void in
if (responseObject != nil) {
var instagramResponse = responseObject as! NSDictionary
var accessToken : String = instagramResponse["credentials"]!["token"] as! String
println(accessToken)
} else {
println(error.localizedDescription)
}
}
This simply gets the response and prints the accessToken.
From here on you can access endpoints to retrieve further data.
Hopefully this helps!
Upvotes: 1