ios - Fitbit OAuth2.0 token 请求(Swift 3)
<p>我正在尝试用OAuth2.0授权我的用户。我当前正在使用以下库:<a href="https://github.com/p2/OAuth2" rel="noreferrer noopener nofollow">https://github.com/p2/OAuth2</a>。<br>这是我的代码:<br><pre><code>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)
</code></pre><br>我的职责是:<br><pre><code>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
}
}
}
</code></pre><br>这是我的日志记录:<br><pre><code> OAuth2: Starting authorization
OAuth2: No access token, checking if a refresh token is available
OAuth2: I don't have a refresh token, not trying to refresh
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=******
</code></pre><br>它工作得很好,没有任何错误,但我只是没有得到访问令牌。<br>我找到的每个教程都在swift 2中。希望你能帮助我!</p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p>不确定这是否能帮到你,但演示应用程序中有一些fitbit的示例。它最后一次更新是在2个月前,所以应该在swift 3中。但如果不是的话,我会提前道歉。<br>位于此处:<a href="https://github.com/OAuthSwift/OAuthSwift/blob/master/Demo/Common/ViewController.swift" rel="noreferrer noopener nofollow">https://github.com/OAuthSwift/OAuthSwift/blob/master/Demo/Common/ViewController.swift</a><br>他们有fitbit和fitbit 2的代码。<br>搜索//mark:fitbit<br>编辑:我的坏,错误的图书馆…<br>我的答案是这个图书馆:<br><a href="https://github.com/OAuthSwift/OAuthSwift" rel="noreferrer noopener nofollow">https://github.com/OAuthSwift/OAuthSwift</a></p>
<p style="font-size: 20px;">关于ios - Fitbit OAuth2.0 token 请求(Swift 3),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41632824/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41632824/
</a>
</p>
页:
[1]