02-23-2016 02:41
02-23-2016 02:41
Here is my swift code . it works properly with thirdparty(OauthSwift) .
I am not clear about two things .
First : I get a token from Fitbit server . What is the expire-time of this token ?
Second : When-time we called
testFitbit2
to get data from Fitbit It appears there is no token send into FitBit .
then why we use token .
Offcourse token have a valueable rule . Please give me a example How token work
override func viewDidLoad() {
super.viewDidLoad()
let oauthswift = OAuth2Swift(
consumerKey: "227G3S",
consumerSecret: "24011c9b27e3a3d87cb249d9b32bbe0b",
authorizeUrl: "https://www.fitbit.com/oauth2/authorize",
responseType: "token"
)
oauthswift.authorizeWithCallbackURL(
NSURL(string: "HealthAnother://oauth-callback/fitbit")!,
scope: "activity+profile+location+sleep+weight", state:"Fitbit",
success: { credential, response, parameters in
print(credential.oauth_token)// Here print a token
self.testFitbit2(oauthswift)
},
failure: { error in
print(error.localizedDescription)
}
)
func testFitbit2(oauthswift: OAuth2Swift) {
oauthswift.client.get("https://api.fitbit.com/1/user/-/profile.json", parameters: [:],
success: {
data, response in
let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: [])
print(jsonDict)
}, failure: { error in
print(error.localizedDescription)
})
}
Best Answer