最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

go - Youtube API get premium views amount - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论