【问题标题】:how to use vimeo advance api如何使用 vimeo 高级 API
【发布时间】:2013-06-18 06:59:34
【问题描述】:

我正在使用 vimeo advance api 来根据 youtube 和日常运动中的查询搜索视频。 vimeo 高级 api 需要 oauth 身份验证。我希望 vimeo 像 vimeo 游乐场一样返回我的 json。 https://developer.vimeo.com/apis/advanced/methods/vimeo.videos.search/playground .我编写以下代码来获取 json 数据,但不知道我得到了谁的 json 数据

- (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);



           }
}

上面的代码返回我访问令牌。但我不知道如何使用该访问令牌来获取 json,就像在 vimeo playground 中一样。请任何人为我完成它我很困惑,因为在 vimeo 网站上他们没有正确的指导我如何使用高级 api

【问题讨论】:

    标签: iphone objective-c oauth vimeo


    【解决方案1】:

    获得访问令牌后,您需要针对“http://vimeo.com/api/rest/v2”端点发出经过身份验证的请求。

    此请求必须遵循您在检索 oauth 令牌时执行的相同 oauth 1.0a 签名过程。

    您还必须通过 querystring 参数提供 api 方法,因此要搜索视频,您需要提供 method=vimeo.videos.search。您可以在操场上的“请求”标题下看到一个示例。

    任何其他参数(例如 format=json)也通过查询字符串处理。

    【讨论】:

      猜你喜欢
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多