&part=snippet,contentDetails,statistics,statusDescription:Thisexampleretrievesavideo
resourceandidentifiesseveralresourcepartsthatshouldbeincludedintheAPIresponse.APIresponse:
{"kind":"youtube#videoListResponse","etag":"\"UCBpFjp2h75_b92t44sqraUcyu0/sDAlsG9NGKfr6v5AlPZKSEZdtqA\"","videos":[{"id":"7lCDEYXw3mM","kind":"youtube#video","etag":"\"UCBpFjp2h75_b92t44sqraUcyu0/iYynQR8AtacsFUwWmrVaw4Smb_Q\"","snippet":{"publishedAt":"2012-06-20T22:45:24.000Z","channelId":"UC_x5XG1OV2P6uZZ5FSM9Ttw","title":"Google I/O 101: Q&A On Using Google APIs","description":"Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0.","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/hqdefault.jpg"}},"categoryId":"28"},"contentDetails":{"duration":"PT15M51S","aspectRatio":"RATIO_16_9"},"statistics":{"viewCount":"3057","likeCount":"25","dislikeCount":"0","favoriteCount":"17","commentCount":"12"},"status":{"uploadStatus":"STATUS_PROCESSED","privacyStatus":"PRIVACY_PUBLIC"}}]}
URL:https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&part=snippet,statisticsDescription:Thisexamplemodifiesthepart
parametervaluesothatthecontentDetails
andstatus
propertiesarenotincludedintheresponse.APIresponse:{"kind":"youtube#videoListResponse","etag":"\"UCBpFjp2h75_b92t44sqraUcyu0/sDAlsG9NGKfr6v5AlPZKSEZdtqA\"","videos":[{"id":"7lCDEYXw3mM","kind":"youtube#video","etag":"\"UCBpFjp2h75_b92t44sqraUcyu0/iYynQR8AtacsFUwWmrVaw4Smb_Q\"","snippet":{"publishedAt":"2012-06-20T22:45:24.000Z","channelId":"UC_x5XG1OV2P6uZZ5FSM9Ttw","title":"Google I/O 101: Q&A On Using Google APIs","description":"Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0.","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/hqdefault.jpg"}},"categoryId":"28"},"statistics":{"viewCount":"3057","likeCount":"25","dislikeCount":"0","favoriteCount":"17","commentCount":"12"}}]}
URL:https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&part=snippet,statistics&fields=items(id,snippet,statistics)Description:Thisexampleaddsthefields
parametertoremoveallkind
andetag
propertiesfromtheAPIresponse.APIresponse:{"videos":[{"id":"7lCDEYXw3mM","snippet":{"publishedAt":"2012-06-20T22:45:24.000Z","channelId":"UC_x5XG1OV2P6uZZ5FSM9Ttw","title":"Google I/O 101: Q&A On Using Google APIs","description":"Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0.","thumbnails":{"default":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/default.jpg"},"medium":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/mqdefault.jpg"},"high":{"url":"https://i.ytimg.com/vi/7lCDEYXw3mM/hqdefault.jpg"}},"categoryId":"28"},"statistics":{"viewCount":"3057","likeCount":"25","dislikeCount":"0","favoriteCount":"17","commentCount":"12"}}]}
URL:https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
&fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statisticsDescription:Thisexamplemodifiesthefields
parameterfromexample3sothatintheAPIresponse,eachvideoresource'ssnippet
objectonlyincludesthechannelId
,title
,andcategoryId
properties.APIresponse:{"videos":[{"id":"7lCDEYXw3mM","snippet":{"channelId":"UC_x5XG1OV2P6uZZ5FSM9Ttw","title":"Google I/O 101: Q&A On Using Google APIs","categoryId":"28"},"statistics":{"viewCount":"3057","likeCount":"25","dislikeCount":"0","favoriteCount":"17","commentCount":"12"}}]}
ETags, a standard part of the HTTP protocol, allow applications to refer to a specific version of a particular API resource. The resource could be an entire feed or an item in that feed. This functionality supports the following use cases:
Caching and conditional retrieval – Your application can cache API resources and their ETags. Then, when your application requests a stored resource again, it specifies the ETag associated with that resource. If the resource has changed, the API returns the modified resource and the ETag associated with that version of the resource. If the resource has not changed, the API returns an HTTP 304 response (Not Modified
), which indicates that the resource has not changed. Your application can reduce latency and bandwidth usage by serving cached resources in this manner.
The client libraries for Google APIs differ in their support of ETags. For example, the JavaScript client library supports ETags via a whitelist for allowed request headers that includes If-Match
and If-None-Match
. The whitelist allows normal browser caching to occur so that if a resource's ETag has not changed, the resource can be served from the browser cache. The Obj-C client, on the other hand, does not support ETags.
Protecting against inadvertent overwrites of changes – ETags help to ensure that multiple API clients don't inadvertently overwrite each other's changes. When updating or deleting a resource, your application can specify the resource's ETag. If the ETag doesn't match the most recent version of that resource, then the API request fails.
Using ETags in your application provides several benefits:
- The API responds more quickly to requests for cached but unchanged resources, yielding lower latency and lower bandwidth usage.
- Your application will not inadvertently overwrite changes to a resource that were made from another API client.
The Google APIs Client Library for JavaScript supports If-Match
and If-None-Match
HTTP request headers, thereby enabling ETags to work within the context of normal browser caching.
Using gzip
You can also reduce the bandwidth needed for each API response by enabling gzip compression. While your application will need additional CPU time to uncompress API responses, the benefit of consuming fewer network resources usually outweighs that cost.
To receive a gzip-encoded response you must do two things:
- Set the
Accept-Encoding
HTTP request header to gzip
. - Modify your user agent to contain the string
gzip
.
The sample HTTP headers below demonstrate these requirements for enabling gzip compression:
Accept-Encoding: gzip User-Agent: my program (gzip)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-31 UTC."],[[["The YouTube Data API v3 requires a Google Account, a project in the Google Developers Console, and enablement of the API, with OAuth 2.0 for user authorization, and the option to use a client library."],["The API provides access to various resource types such as activities, channels, playlists, videos, and others, with supported operations including listing, inserting, updating, and deleting, depending on the resource."],["The API employs a quota system with default limits, different costs for different operations, and a monitoring system, allowing for extensions by requesting them."],["The `part` parameter is mandatory for retrieving resources and specifies which properties to include, while the `fields` parameter further filters the response, reducing data transfer by omitting unnecessary nested properties."],["Performance optimizations include the use of ETags for caching and overwrite protection, and gzip compression to reduce bandwidth usage."]]],["To utilize the YouTube Data API, you need a Google account, a project in the Google Developers Console with the API enabled, and potentially OAuth 2.0 authorization. Key actions include using `list`, `insert`, `update`, and `delete` operations on resources like `videos`, `channels`, and `playlists`. API usage is governed by quotas, with each operation incurring a cost; reading operations usually costs 1 unit, while writing or searching costs much more. Use the `part` and `fields` parameters to optimize requests, and utilize ETags and gzip compression to improve efficiency.\n"]]