GTM OAuth2无法检测到成功的身份验证

时间:2015-06-01 09:52:06

标签: ios iphone oauth-2.0 google-oauth gtm-oauth2

我正在尝试使用GTM OAuth2从Fitbit访问用户数据。对于iOS。 GTMOAuth2ViewControllerTouch正在运行,我可以毫无问题地登录。 登录后,控制器应该能够检测到所述的身份验证:

- (GTMOAuth2Authentication *)authForFitbit {
    NSURL *tokenURL = [NSURL URLWithString:@"https://api.fitbit.com/oauth2/token"];

    // We'll make up an arbitrary redirectURI.  The controller will watch for
    // the server to redirect the web view to this URI, but this URI will not be
    // loaded, so it need not be for any actual web page.
    NSString *redirectURI = @"http://www.notexistcallback.com";

    NSString *clientID = kFitbitClientID;
    NSString *clientSecret = kFitbitClientSecret;
    GTMOAuth2Authentication *auth;
    auth = [GTMOAuth2Authentication     authenticationWithServiceProvider:kFitbitServiceName
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:clientID
                                                     clientSecret:clientSecret];
    return auth;
}

如果我使用真实的网址,那么它会直接加载网址。如果我使用任意URL,它根本不会做任何事情。

检测身份验证的正确设置是什么?

- (void)signInToFitbit {
    [self signOut];

    GTMOAuth2Authentication *auth = [self authForFitbit];
    auth.scope = @"profile";

    if ([auth.clientID length] == 0 || [auth.clientSecret length] == 0) {
        NSString *msg = @"The sample code requires a valid client ID and client secret to sign in.";
        [self displayAlertWithMessage:msg];
        return;
    }

    NSString *keychainItemName = @"OAuth2 Sample: Fitbit";
    if ([self shouldSaveInKeychain]) {
    keychainItemName = kKeychainItemName;
    }

    NSURL *authURL = [NSURL URLWithString:@"https://www.fitbit.com/oauth2/authorize"];

    // Display the authentication view
    SEL sel = @selector(viewController:finishedWithAuth:error:);

    GTMOAuth2ViewControllerTouch *viewController;
    viewController = [GTMOAuth2ViewControllerTouch controllerWithAuthentication:auth
                                                           authorizationURL:authURL
                                                           keychainItemName:keychainItemName
                                                                   delegate:self
                                                           finishedSelector:sel];


    // Now push our sign-in view
    [[self navigationController] pushViewController:viewController animated:YES];
}

以下:

HttpPut

0 个答案:

没有答案