在Youtube api中创建播放列表 [英] create playlist in Youtube api

查看:255
本文介绍了在Youtube api中创建播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过Youtube的文档,但我似乎不明白如何为用户专门为ios创建播放列表。我知道用户需要使用OAuth 2登录才能授予应用访问/权限以创建播放列表

I've looked at Youtube's documentation but I don't seem to understand how to create a playlist for the user specifically for ios. I know the user needs to sign in using OAuth 2 to grant apps access/authority to create a playlist

文档链接: https://developers.google.com/youtube/v3/sample_requests#uploaded_videos

但是给出了这段代码:

POST {base_URL}/playlists?part=snippet
 Request body:
{
'snippet': {
  'title': 'New playlist', 
  'description': 'Sample playlist for Data API',
 }
}

我不知道如何将其转换为适用于ios。我如何反映目标c中的Request主体对象?

I'm not sure how to translate this to work on ios. How would I reflect the Request body object in objective c?

-------更新-----
是否只是使用NSURLSessionUploadTask ?所以我可以发送一个帖子请求,并发送请求正文的字典? sry,IOS空间有点新鲜

-------Update----- Would it just be using NSURLSessionUploadTask? so I can send a post request and also send a dictionary for the request body? sry, a bit new to the IOS space

推荐答案

这是更新!



Google的客户端库已更新。

Here is update!

Client library from Google was updated.

文档: YouTube数据API概述

播放列表文档:播放列表:插入

GitHub客户端库:用于REST的Objective API的Google API客户端库

GitHub client library: Google APIs Client Library for Objective-C For REST

以下是需要安装的播客:

Here are pods need to be install:

pod 'GTMSessionFetcher'
pod 'GTMOAuth2'
pod 'GoogleAPIClientForREST/YouTube’

如果我们认为我们有clientID,clientSecret和范围(阅读文档)那么我们可以创建viewController进行身份验证:

If we think that we have clientID, clientSecret and scope (read documentation) then we can create viewController for authentication:

GTMOAuth2ViewControllerTouch *viewController = [[GTMOAuth2ViewControllerTouch alloc]
                                                    initWithScope:scope
                                                    clientID:kMyClientID
                                                    clientSecret:kMyClientSecret
                                                    keychainItemName: nil
                                                    completionHandler:
                                                    ^(GTMOAuth2ViewControllerTouch *viewController, GTMOAuth2Authentication *auth, NSError *error) {
                                                        [self dismissViewControllerAnimated:NO completion:nil];
                                                        if (!error)
                                                        {
                                                            GTLRYouTubeService *youTubeService = [[GTLRYouTubeService alloc] init];
                                                            youTubeService.authorizer = auth;
                                                            [self createPlaylistWithTitle: @"Title" description: @"description" youtubeService: youtubeService];
                                                        }
                                                    }];
[self presentViewController:viewController animated:YES completion:nil];

创建私人播放列表的方法:

Method that creates private playlist:

- (void)createPlaylistWithTitle:(NSString *)playlistTitle description:(NSString *)playlistDescription youtubeService:(GTLRYouTubeService *)youTubeService
{
    GTLRYouTube_Playlist *playlist = [[GTLRYouTube_Playlist alloc] init];

    GTLRYouTube_PlaylistSnippet *playlistSnippet = [[GTLRYouTube_PlaylistSnippet alloc] init];
    playlistSnippet.title = playlistTitle;
    playlistSnippet.descriptionProperty = playlistDescription;

    GTLRYouTube_PlaylistStatus *playlistStatus = [[GTLRYouTube_PlaylistStatus alloc] init];
    playlistStatus.privacyStatus = @"private";

    playlist.snippet = playlistSnippet;
    playlist.status = playlistStatus;

    GTLRYouTubeQuery_PlaylistsInsert *query = [GTLRYouTubeQuery_PlaylistsInsert queryWithObject:playlist part:@"snippet,status"];
    [youTubeService executeQuery:query completionHandler:^(GTLRServiceTicket *ticket, id object, NSError *error) {
        if (!error)
        {
            NSLog(@"response: %@", object);
        }
    }];
}

这篇关于在Youtube api中创建播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆