菜鸟教程小白 发表于 2022-12-11 18:35:25

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: [
    &#34;client_id&#34;: &#34;******&#34;,//ID from Fitbit
    &#34;client_secret&#34;: &#34;***************************&#34;, //Secret from Fitbit
    &#34;authorize_uri&#34;: &#34;https://www.fitbit.com/oauth2/authorize&#34;,
    &#34;token_uri&#34;: &#34;https://api.fitbit.com/oauth2/token&#34;,
    &#34;redirect_uris&#34;: [&#34;http://google.com/&#34;],   
    &#34;scope&#34;: &#34;profile settings activity nutrition heartrate location nutrition profile settings sleep social weight&#34;,
    &#34;secret_in_body&#34;: true,
    &#34;keychain&#34;: 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(&#34;Authorized! Access token is in `oauth2.accessToken`&#34;)
            print(&#34;Authorized! Additional parameters: \(params)&#34;)
      }
      else {
            print(&#34;Authorization was cancelled or went wrong: \(error)&#34;)   // 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&#39;t have a refresh token, not trying to refresh
OAuth2: Opening authorize URL in system browser: https://www.fitbit.com/oauth2/authorize?state=35701F98&amp;response_type=code&amp;scope=profile+settings+activity+nutrition+heartrate+location+nutrition+profile+settings+sleep+social+weight&amp;redirect_uri=http%3A%2F%2Fgoogle.com%2F&amp;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]
查看完整版本: ios - Fitbit OAuth2.0 token 请​​求(Swift 3)