「Google APIs Client Library for .NET : OAuth 2.0」で、Books APIを使用した例が掲載されている。他のAPIを使用する際にも、やり方は変わらないのだけど、Scope指定方法に多少悩んだのでメモしておく。
Admin Reports APIの場合は、次のように書く。
UserCredential credential;
using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { ReportsService.Scope.AdminReportsUsageReadonly },
"user", CancellationToken.None, new FileDataStore("usage"));
}Admin Reports APIのScopeは2種類ある。どのように指定するかは、Google.Apis.Admin.reports_v1.xmlを参照すると分かりやすい。
- ReportsService.Scope.AdminReportsAuditReadonly
- ReportsService.Scope.AdminReportsUsageReadonly