Search code examples
iosswiftrestoauth-2.0fitbit

How to integrate FitBit Api in IOS app using Swift


First of all I created an account at https://www.fitbit.com Then I careated an app at https://dev.fitbit.com then installed OAuthSwift using cocoa pods and implemented this method in my AppDelegate

    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    if (url.host == "oauth-callback") {
        OAuthSwift.handleOpenURL(url)
    }
    return true
}

now i want to get the data (Name, Steps taken etc) of user account I created at https://www.fitbit.com how can I do that ? I searched but was not able to find any tutorial on fitbit integration. And where to use this information in my code? [![enter image description here][1]][1] So please guide me about next step what should I do to get the data.


Solution

  • FitBit work with OAuth 2.0 API which require Client ID and Secret key. You need these client id and secret key to authenticate with OAuth 2.0 API. There is a blog post related to FitBit integration in iOS with Swift. Lets checkout and learn "How to implement fitbit in iOS" https://appengineer.in/2016/04/30/fitbit-aouth-in-ios-app/

    ex:

    let oauthswift = OAuth2Swift(
            consumerKey:    fitbit_clientID,
            consumerSecret: fitbit_consumer_secret,
            authorizeUrl:   "https://www.fitbit.com/oauth2/authorize",
            accessTokenUrl: "https://api.fitbit.com/oauth2/token",
            responseType:   "token"
        )