首先,我在https://www.fitbit.com创建了一个帐户 然后我在https://dev.fitbit.com关注了一款应用 然后使用cocoa pod安装OAuthSwift并在我的AppDelegate中实现此方法
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.host == "oauth-callback") {
OAuthSwift.handleOpenURL(url)
}
return true
}
现在我想获取我在https://www.fitbit.com创建的用户帐户的数据(名称,步骤等) 我怎样才能做到这一点 ?我搜索但无法找到任何关于fitbit集成的教程。在我的代码中何处使用此信息? 因此,请指导下一步我应该怎样做才能获得数据。
答案 0 :(得分:1)
FitBit使用OAuth 2.0 API,需要客户端ID和密钥。您需要这些客户端ID和密钥才能使用OAuth 2.0 API进行身份验证。 有一篇关于FitBit在iOS中与Swift集成的博客文章。 让我们结帐并学习“如何在iOS中实现fitbit” https://appengineer.in/2016/04/30/fitbit-aouth-in-ios-app/
前:
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"
)
答案 1 :(得分:0)
你有可能用基本的auth而不是OAuth来做吗?我有一个类似的问题,尝试向MailGun发送一些我在应用程序中实现的自动电子邮件。
我能够通过大型HTTP响应使其正常工作。我把完整的路径放到Keys.plist中,这样我就可以将我的代码上传到github并将一些参数分解为变量,这样我就可以在以后的程序中设置它们。
// Email the FBO with desired information
// Parse our Keys.plist so we can use our path
var keys: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Keys", ofType: "plist") {
keys = NSDictionary(contentsOfFile: path)
}
if let dict = keys {
// variablize our https path with API key, recipient and message text
let mailgunAPIPath = dict["mailgunAPIPath"] as? String
let emailRecipient = "bar@foo.com"
let emailMessage = "Testing%20email%20sender%20variables"
// Create a session and fill it with our request
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: NSURL(string: mailgunAPIPath! + "from=FBOGo%20Reservation%20%3Cscheduler@<my domain>.com%3E&to=reservations@<my domain>.com&to=\(emailRecipient)&subject=A%20New%20Reservation%21&text=\(emailMessage)")!)
// POST and report back with any errors and response codes
request.HTTPMethod = "POST"
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
if let error = error {
print(error)
}
if let response = response {
print("url = \(response.URL!)")
print("response = \(response)")
let httpResponse = response as! NSHTTPURLResponse
print("response code = \(httpResponse.statusCode)")
}
})
task.resume()
}
Mailgun Path在Keys.plist中作为名为mailgunAPIPath的字符串,其值为:
https://API:key-<my key>@api.mailgun.net/v3/<my domain>.com/messages?
希望这有帮助!