I am trying to pull data from Youtube Analytics API using R and have hit a wall. I'm getting a Status 403 error. I can confirm that:
- I have tried logging out of all accounts, rebooting, re-authenticating and then logging into 1 account and it didn't work
- I have tried using just the https://www.googleapis.com/auth/youtube.readonly scope (which is supposed to be correct) and all youtube analytics scopes are authorized within the app (each with their own credential key), it didn't work.
- I have tried authenticating from different browsers, it didn't work
- I can confirm that the call worked from https://developers.google.com/apis-explorer/#p/youtubeAnalytics/v2/youtubeAnalytics.reports.query.
UPDATE I have found the solution and updated the code to what is now working
scopes<- c('https://www.googleapis.com/auth/youtube.readonly')
endpoint<- oauth_endpoints('google')
youtubeapp<- oauth_app(appname='Youtube Analytics API',
key=client_id,
secret=client_secret)
youtube_token<- oauth2.0_token(
endpoint= oauth_endpoints('google'),
app = youtubeapp,
scope = scopes)
raw_data<- GET(paste("https://youtubeanalytics.googleapis.com/v2/reports?dimensions=",dimensions,"&endDate=",enddate,"&ids=",ids,"&metrics=",metrics,"&startDate=",startdate,sep=""),
config=youtube_token,content_type('application/json'))
content(raw_data, as= 'text')