$youTubePlaylist->setStatus($playlistStatus); // 4. Call the playlists.insert method to create the playlist. The API // response will contain information about the new playlist. $playlistResponse = $youtube->playlists->insert('snippet,status', $youTubePlaylist, array()); $playlistId = $playlistResponse['id']; // 5. Add a video to the playlist. First, define the resource being added // to the playlist by setting its video ID and kind. $resourceId = new Google_Service_YouTube_ResourceId(); $resourceId->setVideoId('SZj6rAYkYOg'); $resourceId->setKind('youtube#video'); // Then define a snippet for the playlist item. Set the playlist item's // title if you want to display a different value than the title of the // video being added. Add the resource ID and the playlist ID retrieved // in step 4 to the snippet as well. $playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet(); $playlistItemSnippet->setTitle('First video in the test playlist'); $playlistItemSnippet->setPlaylistId($playlistId); $playlistItemSnippet->setResourceId($resourceId); // Finally, create a playlistItem resource and add the snippet to the // resource, then call the playlistItems.insert method to add the playlist // item. $playlistItem = new Google_Service_YouTube_PlaylistItem(); $playlistItem->setSnippet($playlistItemSnippet); $playlistItemResponse = $youtube->playlistItems->insert('snippet,contentDetails', $playlistItem, array()); $htmlBody .= "<h3>New Playlist</h3><ul>"; $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistResponse['snippet']['title'], $playlistResponse['id']); $htmlBody .= '</ul>'; $htmlBody .= "<h3>New PlaylistItem</h3><ul>"; $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItemResponse['snippet']['title'], $playlistItemResponse['id']); $htmlBody .= '</ul>'; } catch (Google_Service_Exception $e) {
fclose($handle); // If you want to make other calls after the file upload, set setDefer back to false $client->setDefer(false); if ($screen_base != 'toplevel_page_youtube-for-wordpress') { $insert_button = '<a class="button button-secondary insert_video_button">insert</a>'; } else { $insert_button = ''; } // if the user selected to upload to a playlist // else we just skip it if ($playlist_id != '') { $resourceId = new Google_Service_YouTube_ResourceId(); $resourceId->setVideoId($status['id']); $resourceId->setKind('youtube#video'); $playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet(); $playlistItemSnippet->setTitle($_POST['video-title']); $playlistItemSnippet->setPlaylistId($playlist_id); $playlistItemSnippet->setResourceId($resourceId); $playlistItem = new Google_Service_YouTube_PlaylistItem(); $playlistItem->setSnippet($playlistItemSnippet); $insertToPlaylistRequest = $youtube->playlistItems->insert('snippet,contentDetails', $playlistItem, array()); } $htmlBody .= '<h3>Content Successfuly Uploaded</h3><p>Your new content should now be viewable from within the <a style="margin-top:-6px;" class="button-secondary" href="?page=youtube-for-wordpress&tab=youtube_plus_browse">browse</a> tab, but may be unavailable until it completes processing.</p><br /><a href="#" class="upload_another_video button-secondary">Upload Another</a>'; // print_r($status); $htmlBody .= '</ul>'; // testing returned data from // YouTube API /******************************/ // $htmlBody .= 'The Privacy Setting Is ...... '. $_POST['video-privacy-settings']; } catch (Google_ServiceException $e) { $htmlBody .= sprintf('<span id="response_message" class="yt4wp-error-alert"><p>An error has occurred: %s. Error #%s</p></span>', htmlspecialchars($e->getMessage(), $e->getCode()));