Search code examples
ryoutube-apiyoutube-analytics-apiyoutube-analytics

YouTube Analytics API is returning 0 for Views & Subscribers Gained


I have made a GET request to try to get my views and subscribers gained on my youtube channel, and I get a 200 status, but the results are 0

startDate <- "2020-05-09"
endDate <- "2020-05-24"
metrics <- "views,subscribersGained"

url <- paste0("https://youtubeanalytics.googleapis.com/v2/reports?",
              "&ids=channel%3D%3DMINE",
              "&metrics=", metrics,
              "&startDate=", startDate,
              "&endDate=", endDate)

temp <- httr::GET(url, token) #Authenticating token worked flawlessly
stop_for_status(temp)
fin <- fromJSON(rawToChar(temp$content))

This call was correct, and returned 0 views and 0 subscribers, which is impossible.

I even went to https://developers.google.com/youtube/analytics/reference/reports/query and tested the api, which returned 0 views, and 0 subscribers gained, BUT when I log into YouTube Studio, it tells me I have 955.5k views.

Is my call technically correct but missing something?


Solution

  • I discovered that the issues was that when going to authenticate, I would click on my account and then I would have the option to click on either my email or my YouTube channel. Naturally I picked YouTube because I want YouTube numbers, but apparently that was the wrong call. It worked correctly for me when I clicked on email.