2014-03-29 59 views
1

我試圖使用其API訪問Vimeo進行身份驗證。我似乎無法解決這個問題。我可以看到vimeo請求從用戶訪問的頁面,並點擊「允許」按鈕它會顯示錯誤。我使用GTM-OAuth2iOS版Vimeo API OAuth 2.0 - 未收到身份驗證令牌

我已經添加下面的代碼:

#import "ViewController.h" 
#import "GTMOAuth2Authentication.h" 
#import "GTMOAuth2ViewControllerTouch.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad{ 
    [super viewDidLoad]; 
    [self signInToVimeo]; 
} 


- (void)didReceiveMemoryWarning{ 
    [super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 


#define ClientID @"clientID" 
#define ClientSecret @"clientSecret" 
#define AuthURL @"https://api.vimeo.com/oauth/authorize" 
#define TokenURL @"https://api.vimeo.com/oauth/request_token" 


- (GTMOAuth2Authentication *)authForVimeo 
{ 
//This URL is defined by the individual 3rd party APIs, be sure to read their documentation 

    NSURL * tokenURL = [NSURL URLWithString:TokenURL]; 
// 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. This needs to match the URI set as the 
// redirect URI when configuring the app with Instagram. 
    NSString * redirectURI = @"Simple-OAuth2://"; 
    GTMOAuth2Authentication * auth; 

    auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"Vimeo" 
                 tokenURL:tokenURL 
                 redirectURI:redirectURI 
                 clientID:ClientID 
                clientSecret:ClientSecret]; 
    auth.scope = @"public"; 
    return auth; 
} 


- (void)signInToVimeo{ 
    GTMOAuth2Authentication * auth = [self authForVimeo]; 

    // Display the authentication view 
    GTMOAuth2ViewControllerTouch * viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth 
                          authorizationURL:[NSURL URLWithString:AuthURL] 
                          keychainItemName:@"VimeoKeychainItem" 
                            delegate:self 
                          finishedSelector:@selector(viewController:finishedWithAuth:error:)]; 
    [self.navigationController pushViewController:viewController animated:YES]; 
    } 


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

    [self.navigationController popToViewController:self animated:NO]; 
    if (error != nil) { 
     UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Vimeo" 
                message:[error localizedDescription] 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
     [alert show]; 
    } else { 

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

@end 

我沒有收到驗證令牌。 Here是點擊「允許」按鈕的屏幕截圖。

回答

0

您的客戶端ID和客戶端密鑰應該是您從Vimeo開發人員網站獲得的密鑰,而不是「clientID」/「clientSecret」。

+0

您是否認爲他會將他的真實client_id和client_secret放在他的帖子中? – nenchev

+0

@nenchev哦大聲笑....我是一個白癡的壞。哈哈 – Supertecnoboff

+0

GTM-OAuth2是隻讀的。我可以在哪裏下載? – Durgaprasad