YouTube

API Reference

experimental feature
The YouTube Analytics API is an experimental API version, which means it is still in development. Until the experimental label is removed, the Deprecation Policy for YouTube APIs won't apply to this version as discussed in the API Terms of Service.

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.

  • To request data for a YouTube user, set the ids parameter value to channel==USER_ID, where USER_ID identifies the currently authenticated YouTube user.
  • To request data for a YouTube CMS content owner, set the ids parameter value to contentOwner==OWNER_NAME, where OWNER_NAME is the CMS user ID for the user.

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.

  • Valid values: json,csv
  • Default value: json
callback Callback function.
  • Name of the JavaScript callback function that handles the response.
  • Used in JavaScript JSON-P requests.
fields Selector specifying a subset of fields to include in the response.
  • Use for better performance.
key API key. (REQUIRED*)
  • *Required unless you provide an OAuth 2.0 token.
  • Your API key identifies your project and provides you with API access, quota, and reports.
  • Obtain your project's API key from the APIs Console.
prettyPrint

Returns response with indentations and line breaks.

  • Returns the response in a human-readable format if true.
  • Default value: true.
  • When this is false, it can reduce the response payload size, which might lead to better performance in some environments.
quotaUser Alternative to userIp.
  • Lets you enforce per-user quotas from a server-side application even in cases when the user's IP address is unknown. This can occur, for example, with applications that run cron jobs on App Engine on a user's behalf.
  • You can choose any arbitrary string that uniquely identifies a user, but it is limited to 40 characters.
  • Overrides userIp if both are provided.
  • Learn more about capping usage.
userIp IP address of the end user for whom the API call is being made.
  • Lets you enforce per-user quotas when calling the API from a server-side application.
  • Learn more about capping usage.

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:

JSON
{
  "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.

CSV
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.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.