0

I want to youtube earning report.

I'm using query_report method for YouTubeAnalytics API.

http://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/YoutubeAnalyticsV1/YouTubeAnalyticsService#query_report-instance_method

Following code has no problem.

youtube_analytics.client.query_report(
  'channel==MINE',
  start_date.to_s,
  end_date.to_s,
  'views'
)

But following code return 401 (authentication failure)

youtube_analytics.client.query_report(
  'channel==MINE',
  start_date.to_s,
  end_date.to_s,
  'earnings'
)

And my omniauth setting is following.

provider :google_oauth2,
  Rails.application.secrets.google['client_id'],
  Rails.application.secrets.google['client_secret'],
  { path_prefix: '/auth/youtube',
    scope: 'email,profile,youtube.readonly,youtubepartner,yt-analytics.readonly,yt-analytics-monetary.readonly',
    prompt: 'consent select_account',
  }

Scope has yt-analytics-monetary.readonly, so I think it should not return 401 error.

Is there any problem in my code?

Thanks.

hidechae
  • 675
  • 1
  • 6
  • 11

1 Answers1

0

Check the access token you are using, it may be the problem instead of the scope. When receiving 401 error it is not only linked to the scopes, it could also be because of other factors like expired or bogus access token or it could also be invalid for some other reason.See OAuth 2.0 Flow.

gerardnimo
  • 1,444
  • 8
  • 10
  • Do you know which scope is needed? I think the scope `email,profile,youtube.readonly,youtubepartner,yt-analytics.readonly,yt-analytics-monetary.readonly` is enough to get earnings value. And the access token I using is not expire, because I can get other metrics value. – hidechae Mar 01 '16 at 01:42