I am working on an application to retrieve information about viewing Youtube videos, the application is used by a "Content Manager" type user.
Today I access data like number of views, watch duration, etc. But also the estimated revenues, the number of ad impressions. But I can't find how getting views from Youtube Premium accounts (and many others datas).
I am using Golang and Youtube dedicated libs, youtubeanalytics in that precice case. Here's my fetching function:
import (
...
"google.golang/api/youtubeanalytics/v2"
...
)
func (f *Fetcher) GetData(ownerID, videoID, startDate, endDate string, metrics []string) {
metricsString := strings.Join(metrics, ",")
call := f.ytaService.Reports.Query().
Ids(fmt.Sprintf("contentOwner==%s", ownerID)).
StartDate(startDate).
EndDate(endDate).
Filters("video==" + videoID).
Metrics(metricsString)
response, err := call.Do()
if err != nil {
if apiErr, ok := err.(*googleapi.Error); ok {
fmt.Printf("API error: %v\n", apiErr)
if apiErr.Code == 400 {
fmt.Println("Erreur 400: Check metrics and dimessions asked.")
}
}
fmt.Printf("Error when getting statistics for video %s: %v\n", videoID, err)
} else {
for _, row := range response.Rows {
for i, v := range row {
fmt.Printf("- %s: %v\n", metrics[i], v)
}
}
}
}
I searched on Google documentation, libs source code and forums, discuted with AI bots. I didn't try downloading and parse csv reports, hoping there's a pure API way to do that.