|
| 1 | +## Samples in this directory: |
| 2 | + |
| 3 | +### [Add a channel section](/youtube/api-samples/blob/master/python/add_channel_section.py) |
| 4 | + |
| 5 | +Method: youtube.channelSections.insert<br> |
| 6 | +Description: This sample calls the API's <code>channelSections.insert</code> method to create channel sections. |
| 7 | +The code accepts a number of command line arguments that let you specify the section's type, display style, title, position, |
| 8 | +and content.<br><br> |
| 9 | +This sample also updates the channel's |
| 10 | +<code><a href="/youtube/v3/docs/channels#brandingSettings.channel.showBrowseView">brandingSettings.channel.showBrowseView</a></code> |
| 11 | +property so that the channel displays content in a browse view (rather than a feed view). A channel's sections are only |
| 12 | +visible if the channel displays content in a browse view.</p><p>More information on channel sections is available in the |
| 13 | +<a href="https://support.google.com/youtube/answer/3027787">YouTube Help Center</a>. |
| 14 | + |
| 15 | +### [Add a featured video](/youtube/api-samples/blob/master/python/add_featured_video.py) |
| 16 | + |
| 17 | +Method: youtube.channels.update<br> |
| 18 | +Description: This sample calls the API's <code>channels.update</code> method to set <code>invideoPromotion</code> |
| 19 | +properties for the channel. |
| 20 | + |
| 21 | +### [Add a channel subscription](/youtube/api-samples/blob/master/python/add_subscription.py) |
| 22 | + |
| 23 | +Method: youtube.subscriptions.insert<br> |
| 24 | +Description: This sample calls the API's <code>subscriptions.insert</code> method to add a subscription to a specified |
| 25 | +channel. |
| 26 | + |
| 27 | +### [Create and manage YouTube video caption tracks](/youtube/api-samples/blob/master/python/captions.py) |
| 28 | + |
| 29 | +Method: youtube.captions.insert, youtube.captions.list, youtube.captions.update, youtube.captions.download, |
| 30 | +youtube.captions.delete<br> |
| 31 | +Description: This sample demonstrates how to use the following API methods to create and manage YouTube video caption |
| 32 | +tracks:<br> |
| 33 | +<ul> |
| 34 | +<li>It calls the <code>captions.insert</code> method with the <code>isDraft</code> parameter set to <code>true</code> |
| 35 | +to upload a caption track in draft status.</li> |
| 36 | +<li>It calls the <code>captions.list</code> method with the <code>videoId</code> parameter to retrieve video caption |
| 37 | +tracks.</li> |
| 38 | +<li>It calls the <code>captions.update</code> method with the caption in the request body to update a caption track.</li> |
| 39 | +<li>It calls the <code>captions.download</code> method to download the caption track.</li> |
| 40 | +<li>It calls the <code>captions.delete</code> method to delete the caption track, using the <code>id</code> parameter to |
| 41 | +identify the caption track.</li> |
| 42 | +</ul> |
| 43 | + |
| 44 | +### [Post a channel bulletin](/youtube/api-samples/blob/master/python/channel_bulletin.py) |
| 45 | + |
| 46 | +Method: youtube.activities.insert<br> |
| 47 | +Description: This sample calls the API's <code>activities.insert</code> method to post a bulletin to the channel |
| 48 | +associated with the request. |
| 49 | + |
| 50 | +### [Set and retrieve localized metadata for a channel](/youtube/api-samples/blob/master/python/channel_localizations.py) |
| 51 | + |
| 52 | +Method: youtube.channels.update, youtube.channels.list<br> |
| 53 | +Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a |
| 54 | +channel:<br> |
| 55 | +<ul> |
| 56 | +<li>It calls the <code>channels.update</code> method to update the default language of a channel's metadata and to add a |
| 57 | +localized version of this metadata in a selected language. Note that to set the default language for a channel resource, |
| 58 | +you actually need to update the <code>brandingSettings.channel.defaultLanguage</code> property.</li> |
| 59 | +<li>It calls the <code>channels.list</code> method with the <code>hl</code> parameter set to a specific language to |
| 60 | +retrieve localized metadata in that language.</li> |
| 61 | +<li>It calls the <code>channels.list</code> method and includes <code>localizations</code> in the <code>part</code> |
| 62 | +parameter value to retrieve all of the localized metadata for that channel.</li> |
| 63 | +</ul> |
| 64 | + |
| 65 | +### [Set and retrieve localized metadata for a channel section](/youtube/api-samples/blob/master/python/channel_section_localizations.py) |
| 66 | + |
| 67 | +Method: youtube.channelSections.update, youtube.channelSections.list<br> |
| 68 | +Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a |
| 69 | +channel section:<br> |
| 70 | +<ul> |
| 71 | +<li>It calls the <code>channelSections.update</code> method to update the default language of a channel section's |
| 72 | +metadata and to add a localized version of this metadata in a selected language.</li> |
| 73 | +<li>It calls the <code>channelSections.list</code> method with the <code>hl</code> parameter set to a specific language |
| 74 | +to retrieve localized metadata in that language.</li> |
| 75 | +<li>It calls the <code>channelSections.list</code> method and includes <code>localizations</code> in the |
| 76 | +<code>part</code> parameter value to retrieve all of the localized metadata for that channel section.</li> |
| 77 | +</ul> |
| 78 | + |
| 79 | +### [Create and manage comments](/youtube/api-samples/blob/master/python/comment_handling.py) |
| 80 | + |
| 81 | +Method: youtube.commentThreads.list, youtube.comments.insert, youtube.comments.list, youtube.comments.update, |
| 82 | +youtube.comments.setModerationStatus, youtube.comments.markAsSpam, youtube.comments.delete<br> |
| 83 | +Description: The following code sample demonstrates how to use the following API methods to create and manage comments:<br> |
| 84 | +<ul> |
| 85 | +<li>It calls the <code>commentThreads.list</code> method with the <code>videoId</code> parameter set to retrieve comments |
| 86 | +for a video.</li> |
| 87 | +<li>It calls the <code>comments.insert</code> method with the <code>parentId</code> parameter set to reply to an existing |
| 88 | +comment.</li> |
| 89 | +<li>It calls the <code>comments.list</code> method with the <code>parentId</code> parameter to retrieve the comments in the |
| 90 | +thread.</li> |
| 91 | +<li>It calls the <code>comments.update</code> method with comment in the request body to update a comment.</li> |
| 92 | +<li>It calls the <code>comments.setModerationStatus</code> method to set the moderation status of the comment, the |
| 93 | +<code>comments.markAsSpam</code> method to mark the comment as spam, and the <code>comments.delete</code> method to |
| 94 | +delete the comment, using the <code>id</code> parameter to identify the comment.</li></ul> |
| 95 | + |
| 96 | +### [Create and manage comment threads](/youtube/api-samples/blob/master/python/comment_threads.py) |
| 97 | + |
| 98 | +Method: youtube.commentThreads.insert, youtube.commentThreads.list, youtube.commentThreads.update<br> |
| 99 | +Description: This sample demonstrates how to use the following API methods to create and manage top-level comments:<br> |
| 100 | +<ul> |
| 101 | +<li>It calls the <code>commentThreads.insert</code> method once with the <code>channelId</code> parameter to create a |
| 102 | +channel comment and once with the <code>videoId</code> parameter to create a video comment.</li> |
| 103 | +<li>It calls the <code>commentThreads.list</code> method once with the <code>channelId</code> parameter to retrieve |
| 104 | +channel comments and once with the <code>videoId</code> parameter to retrieve video comments.</li> |
| 105 | +<li>It calls the <code>commentThreads.update</code> method once to update a video comment and then again to update a |
| 106 | +channel comment. In each case, the request body contains the <code>comment</code> resource being updated.</li> |
| 107 | +</ul> |
| 108 | + |
| 109 | +### [Create a broadcast](/youtube/api-samples/blob/master/python/create_broadcast.py) |
| 110 | + |
| 111 | +Method: youtube.liveBroadcasts.bind,youtube.liveBroadcasts.insert,youtube.liveStreams.insert<br> |
| 112 | +Description: This sample calls the API's <code>liveBroadcasts.insert</code> method to create a broadcast. |
| 113 | + |
| 114 | +### [Create a reporting job](/youtube/api-samples/blob/master/python/create_reporting_job.py) |
| 115 | + |
| 116 | +Method: youtubeReporting.reportTypes.list, youtubeReporting.jobs.create<br> |
| 117 | +Description: This sample demonstrates how to create a reporting job. It calls the <code>reportTypes.list</code> method |
| 118 | +to retrieve a list of available report types. It then calls the <code>jobs.create</code> method to create a new reporting |
| 119 | +job. |
| 120 | + |
| 121 | +### [Search by geolocation](/youtube/api-samples/blob/master/python/geolocation_search.py) |
| 122 | + |
| 123 | +Method: youtube.search.list, youtube.videos.list<br> |
| 124 | +Description: This sample calls the API's <code>search.list</code> method with <code>q</code>, <code>location</code> and |
| 125 | +<code>locationRadius</code> parameters to retrieve search results matching the provided keyword within the radius centered |
| 126 | +at a particular location. Using the video ids from the search result, the sample calls the API's <code>videos.list</code> |
| 127 | +method to retrieve location details of each video. |
| 128 | + |
| 129 | +### [Like a video](/youtube/api-samples/blob/master/python/like_video.py) |
| 130 | + |
| 131 | +Method: youtube.videos.rate<br> |
| 132 | +Description: This sample calls the API's <code>videos.rate</code> method to set a positive rating for a video. |
| 133 | + |
| 134 | +### [Retrieve a channel's broadcasts](/youtube/api-samples/blob/master/python/list_broadcasts.py) |
| 135 | + |
| 136 | +Method: youtube.liveBroadcasts.list<br> |
| 137 | +Description: This sample calls the API's <code>liveBroadcasts.list</code> method to retrieve a list of broadcasts for |
| 138 | +the channel associated with the request. By default, the request retrieves all broadcasts for the channel, but you can |
| 139 | +also specify a value for the <code>--broadcast-status</code> option to only retrieve broadcasts with a particular status. |
| 140 | + |
| 141 | +### [Retrieve a channel's live video streams](/youtube/api-samples/blob/master/python/list_streams.py) |
| 142 | + |
| 143 | +Method: youtube.liveStreams.list<br> |
| 144 | +Description: This sample calls the API's <code>liveStreams.list</code> method to retrieve a list of video stream settings |
| 145 | +that a channel can use to broadcast live events on YouTube. |
| 146 | + |
| 147 | +### [Retrieve my uploads](/youtube/api-samples/blob/master/python/my_uploads.py) |
| 148 | + |
| 149 | +Method: youtube.playlistItems.list<br> |
| 150 | +Description: This sample calls the API's <code>playlistItems.list</code> method to retrieve a list of videos uploaded |
| 151 | +to the channel associated with the request. The code also calls the <code>channels.list</code> method with the |
| 152 | +<code>mine</code> parameter set to <code>true</code> to retrieve the playlist ID that identifies the channel's uploaded |
| 153 | +videos. |
| 154 | + |
| 155 | +### [Set and retrieve localized metadata for a playlist](/youtube/api-samples/blob/master/python/playlist_localizations.py) |
| 156 | + |
| 157 | +Method: youtube.playlists.update, youtube.playlists.list<br> |
| 158 | +Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata for a |
| 159 | +playlist:<br> |
| 160 | +<ul> |
| 161 | +<li>It calls the <code>playlists.update</code> method to update the default language of a playlist's metadata and to add |
| 162 | +a localized version of this metadata in a selected language.</li> |
| 163 | +<li>It calls the <code>playlists.list</code> method with the <code>hl</code> parameter set to a specific language to |
| 164 | +retrieve localized metadata in that language.</li> |
| 165 | +<li>It calls the <code>playlists.list</code> method and includes <code>localizations</code> in the <code>part</code> |
| 166 | +parameter value to retrieve all of the localized metadata for that playlist.</li> |
| 167 | +</ul> |
| 168 | + |
| 169 | +### [Create a playlist](/youtube/api-samples/blob/master/python/playlist_updates.py) |
| 170 | + |
| 171 | +Method: youtube.playlists.insert<br> |
| 172 | +Description: This sample calls the API's <code>playlists.insert</code> method to create a private playlist owned by the |
| 173 | +channel authorizing the request. |
| 174 | + |
| 175 | +### [Retrieve reports](/youtube/api-samples/blob/master/python/retrieve_reports.py) |
| 176 | + |
| 177 | +Method: youtubeReporting.jobs.list, youtubeReporting.reports.list<br> |
| 178 | +Description: This sample demonstrates how to retrieve reports created by a specific job. It calls the |
| 179 | +<code>jobs.list</code> method to retrieve reporting jobs. It then calls the <code>reports.list</code> method with the |
| 180 | +<code>jobId</code> parameter set to a specific job id to retrieve reports created by that job. Finally, the sample |
| 181 | +prints out the download URL for each report. |
| 182 | + |
| 183 | +### [Search by keyword](/youtube/api-samples/blob/master/python/search.py) |
| 184 | + |
| 185 | +Method: youtube.search.list<br> |
| 186 | +Description: This sample calls the API's <code>search.list</code> method to retrieve search results associated with |
| 187 | +a particular keyword. |
| 188 | + |
| 189 | +### [Upload a watermark image and set it for a channel](/youtube/api-samples/blob/master/python/set_watermark.py) |
| 190 | + |
| 191 | +Method: youtube.watermarks.set<br> |
| 192 | +Description: This sample calls the API's <code>watermarks.set</code> method to upload an image and set it as the |
| 193 | +watermark image for a channel. The request must be authorized by the channel that owns the video. |
| 194 | + |
| 195 | +### [Shuffle existing channel sections](/youtube/api-samples/blob/master/python/shuffle_channel_sections.py) |
| 196 | + |
| 197 | +Method: youtube.channelSections.list,youtube.channelSections.update<br> |
| 198 | +Description: This sample calls the API's <code>channelSections.list</code> method to get the list of current channel |
| 199 | +sections, shuffles them, and then calls <code>channelSections.update</code> to change the position of each.<br><br> |
| 200 | +More information on channel sections is available in the |
| 201 | +<a href="https://support.google.com/youtube/answer/3027787">YouTube Help Center</a>. |
| 202 | + |
| 203 | +### [Remove a watermark image from a channel](/youtube/api-samples/blob/master/python/unset_watermark.py) |
| 204 | + |
| 205 | +Method: youtube.watermarks.unset<br> |
| 206 | +Description: This sample calls the API's <code>watermarks.unset</code> method to remove the watermark |
| 207 | +image for a channel. The request must be authorized by the channel that owns the video. |
| 208 | + |
| 209 | +### [Update a video](/youtube/api-samples/blob/master/python/update_video.py) |
| 210 | + |
| 211 | +Method: youtube.videos.update<br> |
| 212 | +Description: This sample calls the API's <code>videos.update</code> method to update a video owned by the channel |
| 213 | +authorizing the request. |
| 214 | + |
| 215 | +### [Upload a banner image and set as channel's banner](/youtube/api-samples/blob/master/python/upload_banner.py) |
| 216 | + |
| 217 | +Method: youtube.channelBanners.insert, youtube.channels.update<br> |
| 218 | +Description: This sample calls the API's <code>channelBanners.insert</code> method to upload an image. With the |
| 219 | +returned URL, the sample calls <code>channels.update</code> method to update channel's banner to this image. |
| 220 | + |
| 221 | +### [Upload a video thumbnail image](/youtube/api-samples/blob/master/python/upload_thumbnail.py) |
| 222 | + |
| 223 | +Method: youtube.thumbnails.set<br> |
| 224 | +Description: This sample calls the API's <code>thumbnails.set</code> method to upload an image and set it as the |
| 225 | +thumbnail image for a video. The request must be authorized by the channel that owns the video. |
| 226 | + |
| 227 | +### [Upload a video](/youtube/api-samples/blob/master/python/upload_video.py) |
| 228 | + |
| 229 | +Method: youtube.videos.insert<br> |
| 230 | +Description: This sample calls the API's <code>videos.insert</code> method to upload a video to the channel associated |
| 231 | +with the request. |
| 232 | + |
| 233 | +### [Set and retrieve localized metadata for a video](/youtube/api-samples/blob/master/python/video_localizations.py) |
| 234 | + |
| 235 | +Method: youtube.videos.update, youtube.videos.list<br> |
| 236 | +Description: This sample demonstrates how to use the following API methods to set and retrieve localized metadata |
| 237 | +for a video:<br> |
| 238 | +<ul> |
| 239 | +<li>It calls the <code>videos.update</code> method to update the default language of a video's metadata and to add |
| 240 | +a localized version of this metadata in a selected language.</li> |
| 241 | +<li>It calls the <code>videos.list</code> method with the <code>hl</code> parameter set to a specific language to |
| 242 | +retrieve localized metadata in that language.</li> |
| 243 | +<li>It calls the <code>videos.list</code> method and includes <code>localizations</code> in the <code>part</code> |
| 244 | +parameter value to retrieve all of the localized metadata for that video.</li> |
| 245 | +</ul> |
| 246 | + |
| 247 | +### [Retrieve top 10 videos by viewcount](/youtube/api-samples/blob/master/python/yt_analytics_report.py) |
| 248 | + |
| 249 | +Method: youtubeAnalytics.reports.query<br> |
| 250 | +Description: This sample calls the API's <code>reports.query</code> method to retrieve YouTube Analytics data. |
| 251 | +By default, the report retrieves the top 10 videos based on viewcounts, and it returns several metrics for those |
| 252 | +videos, sorting the results in reverse order by viewcount. By setting command line parameters, you can use the |
| 253 | +same code to retrieve other reports as well. |
0 commit comments