【发布时间】: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