GTMOAuth2Аутентификация с Vimeo

Осталось два дня, когда я начал изучать OAuth, и у меня есть следующая проблема. У меня проблемы с аутентификацией в Vimeo через GTMOAuth2Authentication. Когда я даю разрешения своему приложению, я получаю эту ошибку на Vimeo:

"Ой, что-то пошло не так! Произошла ошибка. Вы не сможете подключиться..."

Пожалуйста, проверьте мой код и скажите мне, что не так:

- (void)authenticate
{
    GTMOAuth2Authentication * auth = [self configuredAuth];

    // Display the authentication view
    GTMOAuth2ViewControllerTouch * viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth authorizationURL:[NSURL URLWithString:kAuthURL] keychainItemName:kKeychainItemName delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)];

    [_parentView presentViewController:viewController animated:YES completion:nil];
} 

-(GTMOAuth2Authentication *)configuredAuth
{
    NSURL * tokenURL = [NSURL URLWithString:kTokenURL];

    NSString * redirectURI = @"com.mytest.app://";
    GTMOAuth2Authentication * auth;

    auth = [GTMOAuth2Authentication authenticationWithServiceProvider:kKeychainItemName
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:kClientID
                                                     clientSecret:kClientSecret];
    auth.scope = @"public";
    return auth;
}

- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error
{
    NSLog(@"finished");
    NSLog(@"auth access token: %@", auth.accessToken);

    if (error != nil)
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Vimeo"
                                                         message:[error localizedDescription]
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];

        NSLog(@"%@", error);

        [alert show];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Vimeo"
                                                         message:[error localizedDescription]
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];
        [alert show];
    }

    [viewController dismissViewControllerAnimated:YES completion:nil];
}

Я установил тот же URI перенаправления в настройках приложения в Vimeo и, конечно же, настроил его в своем приложении (т.е. я могу из сафари перенаправить в свое приложение через com.mytest.app://). Ну и конечно же в kClientID и kClientSecret определены ID и Secret с сайта developer.vimeo.com.

Когда я закрываю Auth Controller, я всегда получаю эту ошибку:

Error Domain=com.google.GTMOAuth2 Code=-1000 "Операция не может быть завершена. (Ошибка com.google.GTMOAuth2 -1000.)"

Это похоже на проблему с URI перенаправления (обратного вызова), но я не могу понять, что именно создает проблему.


person Vladislav Kovalyov    schedule 15.06.2014    source источник


Ответы (1)


Я не думаю, что ваш URL-адрес перенаправления правильный. Это похоже на идентификатор пакета.

NSString * redirectURI = @"com.mytest.app://";   

Правильно ли вы настроили схему URL?

Перейдите в раздел Xcode -> Настройки проекта -> Основная цель -> Информация -> Типы URL< /сильный>

Убедитесь, что ваши схемы URL-адресов настроены (вы добавили тип URL-адреса с помощью кнопки +), и любое значение, которое у вас есть, соответствует вашему URI перенаправления.

Схемы URL = "схема тестирования" --> "схема тестирования://"

Удачи!

person nenchev    schedule 26.06.2014