【问题标题】:403 Forbidden response with adType dimension in Ad Performance report403 广告效果报告中带有 adType 维度的禁止响应
【发布时间】:2020-06-24 06:23:31
【问题描述】:

我在使用具有 adType 维度的 youtube 分析 api 获取广告效果报告时遇到问题,我收到以下响应:

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Forbidden",
    "reason" : "forbidden"
  } ],
  "message" : "Forbidden"
}

按照文档 (https://developers.google.com/youtube/analytics/channel_reports#ad-performance-reports) 中的说明,我生成了具有示例中指定范围的凭据:

List<String> scopes = Lists.newArrayList(
                "https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
                "https://www.googleapis.com/auth/yt-analytics.readonly",
                "https://www.googleapis.com/auth/youtube.readonly"
        );

// Authorize the request.
Credential credential = Auth.authorize(scopes, "analyticsreports");

那么我就是这样请求报告的:

public QueryResponse getAdPerformaceReportByVideo(String channelId, String videoId, String startDate, String endDate) throws IOException {
        UserCredentials userCredentials = buildUserCredentials();
        userCredentials.refresh();

        final HttpRequestInitializer httpRequestInitializer = new HttpCredentialsAdapter(userCredentials);
        final HttpTransport httpTransport = new NetHttpTransport();
        final JsonFactory jsonFactory = new JacksonFactory();

        YouTubeAnalytics youTubeAnalytics = new YouTubeAnalytics.Builder(httpTransport, jsonFactory, httpRequestInitializer)
                .setApplicationName("myapp")
                .build();

        final YouTubeAnalytics.Reports.Query request = youTubeAnalytics.reports().query();
            try {
                final QueryResponse queryResponse = request.setStartDate(startDate)
                        .setEndDate(endDate)
                        .setIds("channel==" + channelId)
                        .setMetrics("grossRevenue,adImpressions,cpm")
                        .setDimensions("adType,day")
                        .setFilters("video==" + videoId)
                        .execute();

                return queryResponse;
            } catch (IOException e) {
                throw new YoutubeInsightsException("", e);
            }
    }

    private UserCredentials buildUserCredentials() {

        return UserCredentials.newBuilder()
                .setClientSecret(this.clientSecret)
                .setClientId(this.clientId)
                .setRefreshToken(this.youtubeRefreshToken)
                .build();
    }

我只使用刷新令牌在每个请求上获得一个新的访问令牌,这非常适用于使用除此之外的所有其他维度的报告。

查询此维度是否有任何其他特殊要求?

感谢您的帮助。

谢谢。

【问题讨论】:

    标签: youtube-api youtube-data-api


    【解决方案1】:

    我发现我们需要 CMS-Account 在这里检索这些数据:

    How to use YouTube analytics monetary.

    这应该在 API 文档中指定。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    • 我以为我是说需要一个 CSM 帐户,但以后会牢记这一点。谢谢
    猜你喜欢
    • 2018-01-25
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多