0
votes

I'm getting below error when I try to accessing YouTube Reporting Services API using Service Account.

Google.GoogleApiException HResult=0x80131500
Message=Google.Apis.Requests.RequestError The caller does not have permission [403] Errors [ Message[The caller does not have permission] Location[ - ] Reason[forbidden] Domain[global] ]

When I searched online, somewhere I saw we need to have GSuite subscription in order to use service account with API, is it correct?

Here is my code snippet:

String serviceAccountEmail = "[email protected]";

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
1

1 Answers

0
votes

In order to use a service account you must share data with it. I have never heard of using GSuite with a YouTube account you can have the admin try and set up domain wide delegation to the service account. However to my knowledge there is no way to share YouTube data with a service account.

Service accounts are not supported by the YouTube APIs. You will need to use Oauth2 and save your refresh token for access later. The docs only mention OAuth2.