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

查看:23
本文介绍了在 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 中反映请求正文对象?

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

--------更新-----它只是使用 NSURLSessionUploadTask 吗?所以我可以发送一个帖子请求,也可以为请求正文发送一个字典?不好意思,对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-C 的 Google API 客户端库

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

这里是需要安装的 pod:

Here are pods need to be install:

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

如果我们认为我们有 clientID、clientSecret 和 scope(阅读文档),那么我们可以创建 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天全站免登陆