在哪里可以找到 ServiceAccountCredential [英] where can i find ServiceAccountCredential

查看:52
本文介绍了在哪里可以找到 ServiceAccountCredential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asp.net c# 使用 google api,我的目标是使用服务帐户访问 google api.

I am working in google api with asp.net c#, My goal is access google api using service account.

我已经导入了所有需要的 dll 来创建服务帐户来访问管理功能(admin软件开发工具包).

I have imported all needed dlls to create service account to access admin features(admin sdk).

但是我找不到 ServiceAccountCredential.

But i couldn't find ServiceAccountCredential.

如何在我的项目中实现这一点?

How can i implement this in my project?

推荐答案

以下是您在 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
  }

这篇关于在哪里可以找到 ServiceAccountCredential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆