OGeek|极客世界-中国程序员成长平台

标题: ios - Fitbit OAuth2.0 token 请​​求(Swift 3) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:35
标题: ios - Fitbit OAuth2.0 token 请​​求(Swift 3)

我正在尝试用OAuth2.0授权我的用户。我当前正在使用以下库:https://github.com/p2/OAuth2
这是我的代码:

let oauth2 = OAuth2CodeGrant(settings: [
    "client_id": "******",  //ID from Fitbit
    "client_secret": "***************************", //Secret from Fitbit
    "authorize_uri": "https://www.fitbit.com/oauth2/authorize",
    "token_uri": "https://api.fitbit.com/oauth2/token",  
    "redirect_uris": ["http://google.com/"],   
    "scope": "profile settings activity nutrition heartrate location nutrition profile settings sleep social weight",
    "secret_in_body": true,
    "keychain": false,        
    ] as OAuth2JSON)

我的职责是:
func startAuthorization() {
    oauth2.logger = OAuth2DebugLogger(.trace)

    oauth2.authorize() { authParameters, error in
        if let params = authParameters {
            print("Authorized! Access token is in `oauth2.accessToken`")
            print("Authorized! Additional parameters: \(params)")
        }
        else {
            print("Authorization was cancelled or went wrong: \(error)")   // error will not be nil  
        }
    }
}

这是我的日志记录:
[Debug] OAuth2: Starting authorization
[Debug] OAuth2: No access token, checking if a refresh token is available
[Debug] OAuth2: I don't have a refresh token, not trying to refresh
[Debug] OAuth2: Opening authorize URL in system browser: https://www.fitbit.com/oauth2/authorize?state=35701F98&response_type=code&scope=profile+settings+activity+nutrition+heartrate+location+nutrition+profile+settings+sleep+social+weight&redirect_uri=http%3A%2F%2Fgoogle.com%2F&client_id=******

它工作得很好,没有任何错误,但我只是没有得到访问令牌。
我找到的每个教程都在swift 2中。希望你能帮助我!



Best Answer-推荐答案


不确定这是否能帮到你,但演示应用程序中有一些fitbit的示例。它最后一次更新是在2个月前,所以应该在swift 3中。但如果不是的话,我会提前道歉。
位于此处:https://github.com/OAuthSwift/OAuthSwift/blob/master/Demo/Common/ViewController.swift
他们有fitbit和fitbit 2的代码。
搜索//mark:fitbit
编辑:我的坏,错误的图书馆…
我的答案是这个图书馆:
https://github.com/OAuthSwift/OAuthSwift

关于ios - Fitbit OAuth2.0 token 请​​求(Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41632824/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4