【问题标题】:Error in using YouTube Reporting Services with Service Account通过服务帐户使用 YouTube 报告服务时出错
【发布时间】:2018-09-19 06:10:03
【问题描述】:

当我尝试使用服务帐户访问 YouTube Reporting Services API 时出现以下错误。

Google.GoogleApiException HResult=0x80131500
Message=Google.Apis.Requests.RequestError 调用者没有 权限[403]错误[消息[调用者没有 权限]位置[-]原因[禁止]域[全局]]

当我在网上搜索时,我发现我们需要订阅 GSuite 才能使用 API 服务帐户,对吗?

这是我的代码 sn-p:

String serviceAccountEmail = "xxxxxxxxxxxxx@youtubereportingapi.iam.gserviceaccount.com";

var certificate = new X509Certificate2(@"xxxxxxxx.p12", "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer(serviceAccountEmail)
               {
                   Scopes = new[] {  YouTubeReportingService.Scope.YtAnalyticsReadonly, YouTubeReportingService.Scope.YtAnalyticsMonetaryReadonly }
               }.FromCertificate(certificate));

var youtubeReportingService = new YouTubeReportingService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
            });


var jobsListResponse = youtubeReportingService.Jobs.List().Execute(); // Here its throwing error

【问题讨论】:

    标签: google-api youtube-api youtube-analytics-api


    【解决方案1】:

    要使用服务帐号,您必须与其共享数据。我从未听说过将 GSuite 与 YouTube 帐户一起使用,您可以让管理员尝试为服务帐户设置域范围的委派。但是据我所知,没有办法与服务帐户共享 YouTube 数据。

    YouTube API 不支持服务帐户。您将需要使用 Oauth2 并保存刷新令牌以供以后访问。 docs 只提到 OAuth2。

    【讨论】:

      猜你喜欢
      • 2018-06-27
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      相关资源
      最近更新 更多