我看过 Youtube 的文档,但我似乎不明白如何为用户专门为 ios 创建播放列表。我知道用户需要使用 OAuth 2 登录来授予应用程序访问/权限来创建播放列表
文档链接: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 中反映请求主体对象?
- - - -更新 - - -
它只是使用 NSURLSessionUploadTask 吗?所以我可以发送一个发布请求,并发送一个请求正文的字典?抱歉,对于 IOS 领域来说有点陌生
这里是更新!
Google 的客户端库已更新。
文档:YouTube 数据 API 概述
播放列表文档:播放列表:插入
GitHub 客户端库:适用于 REST Objective-C 的 Google API 客户端库
以下是需要安装的 Pod:
pod 'GTMSessionFetcher'
pod 'GTMOAuth2'
pod 'GoogleAPIClientForREST/YouTube’
如果我们认为我们有 clientID、clientSecret 和范围(阅读文档),那么我们可以创建 viewController 进行身份验证:
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];
创建私有播放列表的方法:
- (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);
}
}];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)