0

I am running the following query with Youtube Analytics API

now = datetime.datetime.now()
start_date = (now - datetime.timedelta(days=4)).strftime('%Y-%m-%d')

end_date = (now - datetime.timedelta(days=3)).strftime('%Y-%m-%d')

args = {
    'metrics': 'views,estimatedMinutesWatched',
    'dimensions': 'subscribedStatus',
    'ids': 'channel==<my_channel_id>',
    'startDate': start_date,
    'endDate': end_date
}

analytics_query_response = youtube.reports().query(**args).execute()

I am using youtube analytics api version 2 and changed the end_date parameter to endDate and start_date to startDate and I am getting the following response

{u'kind': u'youtubeAnalytics#resultTable', u'rows': [], u'columnHeaders': [{u'dataType': u'STRING', u'columnType': u'DIMENSION', u'name': u'subscribedStatus'}, {u'dataType': u'INTEGER', u'columnType': u'METRIC', u'name': u'views'}, {u'dataType': u'INTEGER', u'columnType': u'METRIC', u'name': u'estimatedMinutesWatched'}]}

I get the 'rows' in response but it's empty. When I try with the same parameters in Youtube API Explorer, it gives me the result for 'rows'.

What I am doing wrong here?

Rafiul Sabbir
  • 626
  • 6
  • 21

1 Answers1

1

First, you need to add the scope: "Youtube".

Then, try to delete the file: "Google.Apis.Auth.OAuth2.Responses.TokenResponse-..." located in my case at: ".\users\admin\appdata\roamming\YouTubeAnaltycis.Auth.Store"

It´s works for me.

Best regards.

José Luis
  • 11
  • 1
  • My scope variable looks like this: YOUTUBE_READONLY_SCOPE = 'https://www.googleapis.com/auth/yt-analytics.readonly' can you please give me a code sample? Thanks – Rafiul Sabbir May 31 '18 at 10:44
  • I think this is what you need: 'googleapis.com/auth/youtube'. C. Net example: OAuthcredential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, new[] { YouTubeAnalyticsService.Scope.Youtube,YouTubeAnalyticsService.Scope.YtAnalyticsReadonly }, user, CancellationToken.None, new FileDataStore("YouTubeAnalytics.Auth.Store")).Result; – José Luis May 31 '18 at 11:29
  • Where the file **YouTubeAnaltycis.Auth.Store** is located in Ubuntu? – Ravindra Gullapalli Sep 03 '18 at 16:37