How to make API request to get private Vimeo videos in Objective-C?

时光毁灭记忆、已成空白 提交于 2019-12-30 11:12:07

问题


I'm developing an iOS application to play private Vimeo videos. Private videos are given privacy of hiding videos from Vimeo website and given domains so that those videos only will be bought and played in my websites. I have Vimeo PRO account.

I am using VIMNetworking SDK and make authentication in didFinishLaunchingWithOptions() by using client details I got creating app at https://developer.vimeo.com/apps.

Now I have to make API request to get direct video urls. I don't know how to achieve this. Vimeo doesn't give documentation for objective-c. By using below code I get public video response but not working for private videos.

 [[VIMSession sharedSession].client requestURI:@"/videos/4378389" completionBlock:^(VIMServerResponse *response, NSError *error) {        
        id JSONObject = response.result;
        NSLog(@"JSONObject: %@", JSONObject);
    }];

I even tried this code to get private videos. But I get in response.

 VIMClient *client = [[VIMClient alloc] initWithDefaultBaseURL];

    client.requestSerializer = [AFJSONRequestSerializer serializer];

    [client.requestSerializer setValue:@"application/vnd.vimeo.*+json; version=3.2" forHTTPHeaderField:@"Accept"];
     [client.requestSerializer setValue:@"my_client_id" forHTTPHeaderField:@"Authorization"];


    [client requestURI:@"https://api.vimeo.com/me/videos" completionBlock:^(VIMServerResponse *response, NSError *error)
    {

        id JSONObject = response.result;
        NSLog(@"JSONObject: %@", JSONObject);

    }];

And there's the third way with getting these errors: "Request failed: unauthorized (401)" and "Request failed: unacceptable content-type: application/vnd.vimeo.error+json". Its a long error description.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSDictionary *param = @{@"response_type" : @"code", @"client_id" : @"my_cleint_id", @"redirect_uri" : @"vimeo{my_cleint_id}://auth", @"state" : @"exercise"};

[manager GET:@"https://api.vimeo.com/me/videos" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject)
 {

     NSLog(@"Forgot Password JSON: %@",responseObject);


 }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error.description);

      }];

Is it something with access_token that I need to pass? if yes then how to get this access_token? I'm so stuck here. Your little help will be appreciated. Thank you.


回答1:


Vimeo implements OAuth 2.0 Bearer Tokens. You should use it like this:

[serializer setValue:@"Bearer your_token_here" forHTTPHeaderField:@"Authorization"];

It is described in details here



来源:https://stackoverflow.com/questions/38238569/how-to-make-api-request-to-get-private-vimeo-videos-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!