The YouTube Analytics API currently provides a single method that lets you retrieve Analytics reports for a YouTube channel. Each request must use query parameters to specify the channel ID, a start date, an end date, and at least one metric. You may also provide additional query parameters, such as dimensions, filters, or sorting instructions.
The Available Reports document identifies the different reports that you can retrieve. For each report, it lists the dimensions that are used to aggregate data, available metrics, and supported filtering options.
Request
To retrieve YouTube Analytics data via the API, send a GET
request to the following URL:
https://www.googleapis.com/youtube/analytics/v1/reports
Authorization
This request requires authorization with the following scope:
https://www.googleapis.com/auth/yt-analytics.readonly
See the authentication guide for detailed instructions on implementing OAuth 2.0 authentication in your application.
Parameters
The following tables list the API's required, optional, and standard query parameters. Standard parameters are optional parameters that could be used for any Analytics API request. For example, the standard alt
parameter specifies whether the API response should be in JSON or CSV format. (Since the API currently only supports a single method, the standard parameters are listed below as well.)
Parameter Name | Value | Description |
---|---|---|
Required Parameters | ||
end-date |
string |
The end date for fetching YouTube Analytics data. The value should be in
YYYY-MM-DD format.
|
ids |
string |
Identifies the YouTube channel or content owner for which you are retrieving YouTube Analytics data.
|
metrics |
string |
A comma-separated list of YouTube Analytics metrics, such as views or likes,dislikes . See the Available Reports document for a list of the reports that you can retrieve and the metrics available in each report, and see the Metrics document for definitions of those metrics.
|
start-date |
string |
The start date for fetching YouTube Analytics data. The value should be in YYYY-MM-DD format.
|
Optional Parameters | ||
dimensions |
string |
A comma-separated list of YouTube Analytics dimensions, such as video or ageGroup,gender . See the Available Reports document for a list of the reports that you can retrieve and the dimensions used for those reports. Also see the Dimensions document for definitions of those dimensions.
|
filters |
string |
A list of filters that should be applied when retrieving YouTube Analytics data. The Available Reports document identifies the dimensions that can be used to filter each report, and the Dimensions document defines those dimensions. If a request uses multiple filters, join them together with a semicolon (; ), and the returned result table will satisfy both filters. For example, a filters parameter value of video==dMH0bHeiRNg;country==IT restricts the result set to include data for the given video in Italy.
|
max-results |
integer |
The maximum number of rows to include in the response. |
sort |
string |
A comma-separated list of dimensions or metrics that determine the sort order for YouTube Analytics data. By default the sort order is ascending. The '-' prefix causes descending sort order. |
start-index |
integer |
The 1-based index of the first entity to retrieve. (The default value is 1 .) Use this parameter as a pagination mechanism along with the max-results parameter.
|
Standard Parameters | ||
access_token |
OAuth 2.0 token for the current user. |
|
alt |
Data format for the response. |
|
callback |
Callback function. |
|
fields |
Selector specifying a subset of fields to include in the response. |
|
key |
API key. (REQUIRED*) |
|
prettyPrint |
Returns response with indentations and line breaks. |
|
quotaUser |
Alternative to userIp . |
|
userIp |
IP address of the end user for whom the API call is being made. |
|
Request body
Do not supply a request body for this method.
Response
As noted in the alt
parameter definition, the API can return responses in JSON or CSV format. Information about the response body for each type is shown below:
{ "kind": "youtubeAnalytics#resultTable", "columnHeaders": [ { "name": string, "dataType": string, "columnType": string }, ... more headers ... ], "rows": [ [ {value}, {value}, ... ] ] }
Property Name | Value | Description |
---|---|---|
kind |
string |
This value specifies the type of data included in the API response. For the query method, the kind property value will be youtubeAnalytics#resultTable . However, if the API adds support for other methods, API responses for those methods may introduce other kind property values. |
columnHeaders[] |
list |
This value specifies information about the data returned in the rows fields. Each item in the columnHeaders list identifies a field returned in the rows value, which contains a list of comma-delimited data. The columnHeaders list will begin with the dimensions specified in the API request, which will be followed by the metrics specified in the API request. The order of both dimensions and metrics will match the ordering in the API request. For example, if the API request contains the parameters dimensions=ageGroup,gender&metrics=viewerPercentage , the API response will return columns in this order: ageGroup ,gender ,viewerPercentage . |
columnHeaders[].name |
string |
The name of the dimension or metric. |
columnHeaders[].columnType |
string |
The type of the column (DIMENSION or METRIC ). |
columnHeaders[].dataType |
string |
The type of the data in the column (STRING , INTEGER , FLOAT , etc.). |
rows[] |
list |
The list contains all rows of the result table. Each item in the list is an array that contains comma-delimited data corresponding to a single row of data. The order of the comma-delimited data fields will match the order of the columns listed in the
columnHeaders field.If no data is available for the given query, the rows element will be omitted from the response.The response for a query with the day dimension will not contain rows for the most recent days. |
day, views, likes, ... "2012-01-01", 12.0, 3, ... "2012-01-02", 16.0, 2, ... "2012-01-03", 18.0, 8, ... ...
Try it!
Use the API Explorer to call this API and see the API request and response.