【发布时间】:2016-07-21 06:49:29
【问题描述】:
刚开始使用 Google API。 在我的 Google Cloud Platform 帐户中,我为域范围的委派创建了一个服务帐户。我为此服务帐户保存了一个 json 格式的私钥文件。
在我的测试应用程序中,我正在创建一个 GoogleCredential 实例:
var credential =
GoogleCredential.FromStream(new FileStream("privatekey.json", FileMode.Open, FileAccess.Read))
.CreateScoped(Scopes);
如何设置我想模拟的用户? 使用 p12 私钥时,我可以执行以下操作:
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("xxx@developer.gserviceaccount.com") //service Account id
{
Scopes = Scopes,
User = "admin@xxx.com" //the user to be impersonated
}.FromCertificate(new X509Certificate2(@"xxx.p12", "notasecret", X509KeyStorageFlags.Exportable)));
但是我如何使用 GoogleCredential 和 json privatkey 文件来“简单”地做到这一点?
亲切的问候
【问题讨论】:
标签: c# .net google-api google-api-dotnet-client