• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - Fitbit OAuth2.0 token 请​​求(Swift 3)

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:35:25 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试用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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap