且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在哪里可以找到 ServiceAccountCredential

更新时间:2022-12-23 14:38:30

以下是您在 2017 年的做法:

Here's how you do it in 2017:

为服务帐号创建一个私钥作为 JSON 文件

Create a private key for the service account as a JSON file

将下载的文件放在您的项目中(用于开发)或在您的构建过程中烘焙它

Put the downloaded file in your project (for development) or bake it in your build process

在中引用 Google.Apis.Auth 包你的代码

Reference the Google.Apis.Auth package in your code

  using (var stream = new FileStream("key.json", FileMode.Open, FileAccess.Read))
  {
      var credential = GoogleCredential.FromStream(stream)
                                       .CreateScoped(scopes)
                                       .UnderlyingCredential as ServiceAccountCredential;

      //profit
  }