Prerequisites for this code sample: - Java 1.6 - Apache Maven (http://maven.apache.org) Before running the sample, client_secrets.json must be populated with a client ID and client secret. You can create an ID/secret pair at: https://code.google.com/apis/console To build this code sample from the command line, type: mvn compile To run a code sample from the command line, enter the following: mvn exec:java -Dexec.mainClass="FULL_CLASS_NAME" For samples that require arguments, also specify -Dexec.args, e.g.: mvn exec:java -Dexec.mainClass="FULL_CLASS_NAME" -Dexec.args="arg1 arg2" For more instructions about how to set up Maven and/or your IDE to run YouTube API samples, see this video: http://youtu.be/pb_t5_ShQOM ## Samples in this directory: ### [Authorize a request](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/Auth.java) Description: This sample demonstrates how to use OAuth 2.0 to authorize an application to access resources on a user's behalf. ### [Add a channel subscription](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/AddSubscription.java) Method: youtube.subscriptions.insert
Description: This sample calls the API's subscriptions.insert method to add a subscription to a specified channel. ### [Add a featured video](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/InvideoProgramming.java) Method: youtube.channels.update
Description: This sample calls the API's channels.update method to set invideoPromotion properties for the channel. ### [Create a playlist](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/PlaylistUpdates.java) Method: youtube.playlists.insert
Description: This sample calls the API's playlists.insert method to create a private playlist owned by the channel authorizing the request. ### [Create and manage comments](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/CommentHandling.java) Method: youtube.commentThreads.list, youtube.comments.insert, youtube.comments.list, youtube.comments.update, youtube.comments.setModerationStatus, youtube.comments.markAsSpam, youtube.comments.delete
Description: This sample demonstrates how to use the following API methods to create and manage comments:
### [Create and manage comment threads](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/CommentThreads.java) Method: youtube.commentThreads.insert, youtube.commentThreads.list, youtube.commentThreads.update
Description: This sample demonstrates how to use the following API methods to create and manage top-level comments:
### [Create and manage YouTube video caption tracks](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/Captions.java) Method: youtube.captions.insert, youtube.captions.list, youtube.captions.update, youtube.captions.download, youtube.captions.delete
Description: This sample demonstrates how to use the following API methods to create and manage YouTube video caption tracks:
### [Post a channel bulletin](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/ChannelBulletin.java) Method: youtube.activities.insert
Description: This sample calls the API's activities.insert method to post a bulletin to the channel associated with the request. ### [Retrieve my uploads](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/MyUploads.java) Method: youtube.playlistItems.list
Description: This sample calls the API's playlistItems.list method to retrieve a list of videos uploaded to the channel associated with the request. The code also calls the channels.list method with the mine parameter set to true to retrieve the playlist ID that identifies the channel's uploaded videos. ### [Search by keyword](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/Search.java) Method: youtube.search.list
Description: This sample calls the API's search.list method to retrieve search results associated with a particular keyword. ### [Search by location](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/GeolocationSearch.java) Method: youtube.search.list, youtube.videos.list
Description: This sample calls the API's search.list method with the type, q, location, and locationRadius parameters to retrieve search results matching the provided keyword within the radius centered at a particular location. Using the video IDs from the search result, the sample calls the API's videos.list method to retrieve location details of each video. ### [Set and retrieve localized channel metadata](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/ChannelLocalizations.java) Method: youtube.channels.update, youtube.channels.list
Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a channel:
### [Set and retrieve localized channel section metadata](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/ChannelSectionLocalizations.java) Method: youtube.channelSections.update, youtube.channelSections.list
Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a channel section:
### [Set and retrieve localized playlist metadata](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/PlaylistLocalizations.java) Method: youtube.playlists.update, youtube.playlists.list
Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a playlist:
### [Set and retrieve localized video metadata](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/VideoLocalizations.java) Method: youtube.videos.update, youtube.videos.list
Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a video:
### [Update a video](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/UpdateVideo.java) Method: youtube.videos.update
Description: This sample calls the API's videos.update method to update a video owned by the channel authorizing the request. ### [Upload a custom video thumbnail image](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/UploadThumbnail.java) Method: youtube.thumbnails.set
Description: This sample calls the API's thumbnails.set method to upload an image and set it as the thumbnail image for a video. The request must be authorized by the channel that owns the video. ### [Upload a video](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/UploadVideo.java) Method: youtube.videos.insert
Description: This sample calls the API's videos.insert method to upload a video to the channel associated with the request. ### [Retrieve top 10 videos by viewcount](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/analytics/YouTubeAnalyticsReports.java) Method: youtubeAnalytics.reports.query
Description: This sample calls the API's reports.query method to retrieve YouTube Analytics data. By default, the report retrieves the top 10 videos based on viewcounts, and it returns several metrics for those videos, sorting the results in reverse order by viewcount. By setting command line parameters, you can use the same code to retrieve other reports as well. ### [Create a reporting job](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/reporting/CreateReportingJob.java) Method: youtubeReporting.reportTypes.list, youtubeReporting.jobs.create
Description: This sample demonstrates how to create a reporting job. It calls the reportTypes.list method to retrieve a list of available report types. It then calls the jobs.create method to create a new reporting job. ### [Retrieve reports](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/reporting/RetrieveReports.java) Method: youtubeReporting.jobs.list, youtubeReporting.reports.list
Description: This sample demonstrates how to retrieve reports created by a specific job. It calls the jobs.list method to retrieve reporting jobs. It then calls the reports.list method with the jobId parameter set to a specific job ID to retrieve reports created by that job. Finally, the sample prints out the download URL for each report. ### [Create a broadcast and stream](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/CreateBroadcast.java) Method: youtube.liveBroadcasts.bind,youtube.liveBroadcasts.insert,youtube.liveStreams.insert
Description: This sample calls the API's liveBroadcasts.insert and liveStreams.insert methods to create a broadcast and a stream. Then, it calls the liveBroadcasts.bind method to bind the stream to the broadcast. ### [Retrieve a channel's broadcasts](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/ListBroadcasts.java) Method: youtube.liveBroadcasts.list
Description: This sample calls the API's liveBroadcasts.list method to retrieve a list of broadcasts for the channel associated with the request. By default, the request retrieves all broadcasts for the channel, but you can also specify a value for the --broadcast-status option to only retrieve broadcasts with a particular status. ### [Retrieve a channel's live video streams](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/ListStreams.java) Method: youtube.liveStreams.list
Description: This sample calls the API's liveStreams.list method to retrieve a list of video stream settings that a channel can use to broadcast live events on YouTube. ### [Get a live chat id](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/GetLiveChatId.java) Methods: youtube.videos.list, youtube.liveBroadcasts.list
Description: This sample retrieves the live chat ID from either a videoId parameter or the live broadcast for the authorized user's channel. The liveChatId is required for other samples that interact with live chat. ### [Insert a live chat message](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/InsertLiveChatMessage.java) Method: youtube.liveChatMessages.insert
Description: This sample inserts a live chat message into the the specified video or the live broadcast for the authorized user's channel. ### [Delete a live chat message](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/DeleteLiveChatMessage.java) Method: youtube.liveChatMessages.delete
Description: This sample deletes the specified live chat message. ### [List live chat messages](/java/src/main/java/com/google/api/services/samples/youtube/cmdline/live/ListLiveChatMessages.java) Method: youtube.liveChatMessages.list
Description: This sample lists live chat messages from the specified video or from the live broadcast for the authorized user's channel.