【问题标题】:Fitbit and OAuth 2.0Fitbit 和 OAuth 2.0
【发布时间】:2015-08-10 07:53:02
【问题描述】:

我正在尝试将 fitbit 集成添加到 iOS 应用程序中。我惊讶地发现这是多么困难......我想象会有一个 iOS SDK。

无论如何,我都在尝试通过基于 Web 的 API 提取数据。它使用 OAuth 1 和 2。

我都尝试过,但在 OAuth 2.0 方面取得了更大的进步。

我目前正在使用 AFOAuth2Manager 进行连接。不幸的是,它运行不佳。

使用带有我的帐户信息的演示代码,我收到以下错误:

请求失败:不可接受的内容类型:text/html

通过添加:

OAuth2Manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

该错误消失了,但出现了一个新错误:

JSON 文本不以数组或对象开头,并且选项允许 片段未设置。

这是我用来发出请求的代码:

AFOAuth2Manager *OAuth2Manager =
        [[AFOAuth2Manager alloc] initWithBaseURL:baseURL
                                        clientID:@"CLIENT_ID"
                                          secret:@"CLIENT_SECRET"];

OAuth2Manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

[OAuth2Manager authenticateUsingOAuthWithURLString:@"/oauth2/authorize"
                                          username:USER_NAME
                                          password:USER_PASSWORD
                                             scope:@"activity"
                                           success: ^(AFOAuthCredential *credential) {
    NSLog(@"Token: %@", credential.accessToken);
}
                                           failure: ^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

我想尝试添加 NSJSONReadingAllowFragments。但是一直无法将其无误地放入代码中。

//OAuth2Manager.responseSerializer.readingOptions = NSJSONReadingAllowFragments;

【问题讨论】:

标签: ios oauth afnetworking afnetworking-2 fitbit


【解决方案1】:

就我而言,我将错误的路径附加到了基本 URL。例如,我的路径是“/oauth/access_token”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 2019-06-06
    • 2016-03-28
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    相关资源
    最近更新 更多