Use OAuth to access data from a popular site such as Strava inside an iOS application.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5034-accessing-data-using-oauth
Use OAuth to access data from a popular site such as Strava inside an iOS application.
Hi Spiro,
Thanks for the screencast. I have a suggestion. Since this is a screencast to introduce, explain and teach someone else something, is it possible for you to speak a little bit slower for future ones? All other video courses and screencasts I have watched so far, in my opinion, are presented in appropriate speed, feeling comfortable when watching.
Thanks.
Mike
Totally understand! I tried to pack a lot into this one to keep it bite sized. But thanks for your suggestion
Thanks for your prompt response. Learned a lot from this short screencast.
This was not of the quality I expect from RayWenderlich. The presenter was hurried and the code was shown at a blindingly fast speed.
You can do better. Slow down. Show the code clearly and explain the usage of the API as you go along.
Do I need to create a Strava app in order to run the sample code? How do I get the following ?
static let API:String = “XXXXXXXXXXXXXXXXXXXXXXXXXXX”
static let consumerKey:String = “XXXXXXXXXXXXXXXXXXXXXXXXXXX”
static let consumerSecret:String = “XXXXXXXXXXXXXXXXXXXXXXXXXXX”
Yup! https://developers.strava.com
On that page there is an option Create & Manage Your App
Once you create a new application those items will be revealed.
Also, if you can’t find the API url, it is: “https://www.strava.com/api/v3/athlete/activities”
I don’t think anyone would mind if your screencast had two installments. Talking slowly is good. We can always do the 1.5x or 2.0x speedups if needed.
When I click on Create & Manage Your App, it asks for a website and Authorization Callback domain. What do I use for these?
When you set your application up with Strava you’ll want to use: 127.0.0.1
as your Authorization Callback Domain . For the website field, you can use anything – that might be the marketing site for your app. For my demo app. I used “http://www.runxtrain.com”. The website is just a parameter that Strava chooses to require. The callback URL is part of the oAuth process. In the video I talk about how Strava needs to redirect somewhere.
Following the Strava app setup, inside the sample application, you’ll want to set the callbackURL parameter like described in video. I use my bundle identifier with the local IP address 127.0.0.1, which is the domain that I use inside the Authorization Callback Domain on the Strava end. It should look like this inside AppConfig.swift:
static let appversion:String = “1.00022”
static let API:String = “https://www.strava.com/api/v3/athlete/activities”
static let consumerKey:String = YOUR_CLIENT_ID
static let consumerSecret:String = YOUR_CLIENT_SECRET
static let authorizeURL:String = “https://www.strava.com/oauth/authorize”
static let accessTokenUrl:String = “https://www.strava.com/oauth/token”
static let responseType:String = “code”
static let callBackURL:String = “com.razeware.strava://127.0.0.1”
static let scope:String = “view_private,write”
static let state:String = “123”
Following those steps-- the next step that’s described in the video is important for all these to work. You’ll need to make sure to set that URL scheme inside your Info.plist so it has the bundle identifier to match what you’ve set as the first part of the callback URL parameter inside AppConfig. If you are following along in the video (and for demonstration purposes), that would be com.razeware.strava
Will there be a follow-on screencast showing how to setup the server side OAuth stuff? If my app is client/server based it seems like I’d want to be running my own OAuth server.
At the moment, there are no immediate plans for a screencast on setting up your own OAuth server (at least that I’m aware of).
Hi, I see the usage of Notification Center adding observers, will you explain why you choose to go that route?
I use observers just to demonstrate an event can be received following the API callback in other parts of the app.