2013-06-18 104 views
0

我使用vimeo advance api來搜索視頻,比如在YouTube和日常運動中查詢視頻。 vimeo advance api需要oauth認證。我想讓vimeo像vimeo操場一樣返回我的json。 https://developer.vimeo.com/apis/advanced/methods/vimeo.videos.search/playground 。我寫下面的代碼來獲取JSON數據,但不知道誰是我的JSON數據如何使用vimeo advance api

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    SBJsonParser *json = [[SBJsonParser alloc]init]; 
    // Do any additional setup after loading the view, typically from a nib. 

    OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"0c5e6dd9b8fa5f8d91563332da03912ac8c2e15d" 
                secret:@"744eb15d911ee3607f7006f1f4ad7eb17a94eec6"]; 

    NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/request_token"]; 


    OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url 
                    consumer:consumer 
                     token:nil 
                     realm:nil 
                  signatureProvider:nil]; 

[request setParameters: [NSArray arrayWithObjects: [[OARequestParameter alloc] initWithName: @"oauth_callback" value: @"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.search&qdfduery=amir+khan"] ,nil]]; 

    [request setHTTPMethod:@"GET"]; 

    OADataFetcher *fetcher = [[OADataFetcher alloc] init]; 

    [fetcher fetchDataWithRequest:request 

         delegate:self 

       didFinishSelector:@selector(requestTokenTicket:didFinishWithData:) 

        didFailSelector:nil]; 



} 


- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data { 
    if (ticket.didSucceed) 
    { 




    NSString *responseBody = [[NSString alloc] initWithData:data 
                encoding:NSUTF8StringEncoding]; 
     OAToken *requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody]; 
     NSLog(@"data %@",requestToken); 

     OAMutableURLRequest *request; 

     if (self.accessToken != nil) { 
      self.accessToken = nil; 
     } 

     self.accessToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody]; 
     NSLog(@"access token key %@",self.accessToken.key) ; 
     NSLog(@"access token secret %@",self.accessToken.secret) ; 
     NSURL *url = [NSURL URLWithString:@"https://vimeo.com/oauth/authorize"]; 
     OAConsumer *consumer = [[OAConsumer alloc] initWithKey:self.accessToken.key 
                 secret:self.accessToken.secret]; 

     request = [[OAMutableURLRequest alloc] initWithURL:url 
                consumer:consumer 
                token:self.accessToken 
                realm:nil 
             signatureProvider:nil]; 

     OARequestParameter *p0 = [[OARequestParameter alloc] initWithName:@"oauth_token" value:self.accessToken.key]; 
     NSArray *params = [NSArray arrayWithObject:p0]; 
     [request setParameters:params]; 
     [webView loadRequest:request]; 
     NSLog(@"request %@",request); 



      } 
} 

上面的代碼返回訪問令牌。但我不知道如何使用該訪問令牌來獲得像vimeo操場中的json。好心人完成對我來說我很困惑,因爲Vimeo上他們的網站是沒有正確的指導我如何使用API​​提前

回答

1

一旦你有一個訪問令牌,你需要做反對「http://vimeo.com/api/rest/v2」端點驗證的請求。

此請求必須遵循您在檢索oauth標記時執行的相同oauth 1.0a簽名過程。

您還必須通過querystring參數提供api方法,以便搜索您將提供method = vimeo.videos.search的視頻。您可以在「請求」標題下的操場上看到此示例。

任何其他參數(例如format = json)也通過查詢字符串處理。