create playlist in Youtube api

后端 未结 2 1509
情话喂你
情话喂你 2021-01-07 11:49

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 O

2条回答
  •  甜味超标
    2021-01-07 12:49

    You are correct, you need to grant apps access to create a playlist by using OAuth 2.0. It is generally a best practice to request scopes incrementally at the time access is required rather than up front.

    Here's a code snippet how to create a playlist via YouTube API in IOS:

    GTMOAuth2ViewControllerTouch *viewController = [[GTMOAuth2ViewControllerTouch alloc]
    initWithScope:scope
    clientID:clientId
    clientSecret:clientSecret
    keychainItemName:keychainItemName
    completionHandler:
    ^(GTMOAuth2ViewControllerTouch *viewController, GTMOAuth2Authentication *auth, NSError *error) {
    if (error) {
    [SVProgressHUD showErrorWithStatus:error.localizedDescription];
    } else {
    GTLServiceYouTube *service = [FZMYoutubeSearchService sharedYoutubeService];
    service.authorizer = auth;
    
    GTLYouTubePlaylist *playlist = [[GTLYouTubePlaylist alloc] init];
    
    GTLYouTubePlaylistSnippet *playlistSnippet = [[GTLYouTubePlaylistSnippet alloc] init];
    playlistSnippet.title = @"this is my great playlist";
    playlistSnippet.descriptionProperty = @"and this is description";
    
    GTLYouTubePlaylistStatus *playlistStatus = [[GTLYouTubePlaylistStatus alloc] init];
    playlistStatus.privacyStatus = @"private";
    
    playlist.snippet = playlistSnippet;
    playlist.status = playlistStatus;
    
    GTLQueryYouTube *query = [GTLQueryYouTube    queryForPlaylistsInsertWithObject:playlist part:@"snippet,status"];
    [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,      id object, NSError *error) {
    if (error) {
    NSLog(@"error: %@", error);
    

提交回复
热议问题