Валерий
Валерий

Reputation: 11

AVERAGE VIEW DURATION

How to get AVERAGE VIEW DURATION on youtube api

Upvotes: 0

Views: 331

Answers (1)

Chiwda
Chiwda

Reputation: 1354

Slightly modified from the YouTube Analytics API's Sample Application

var request = gapi.client.youtubeAnalytics.reports.query({
    // The start-date and end-date parameters must be YYYY-MM-DD strings.
    'start-date': formatDateString(lastMonth),
    'end-date': formatDateString(today),
    // At this time, you need to explicitly specify channel==channelId.
    // See https://developers.google.com/youtube/analytics/v1/#ids
    ids: 'channel==' + channelId,
    dimensions: 'day',
    sort: 'day',
    // See https://developers.google.com/youtube/analytics/v1/available_reports
    // for details about the different filters and metrics you can request
    // if the "dimensions" parameter value is "day".
    metrics: 'averageViewDuration',
    filters: 'video==' + videoId
  });

Of course this assumes you have done the work of authenticating and retrieving the videoid.

Upvotes: 1

Related Questions