当我尝试使用服务帐户授权gmail api时,我收到以下错误
"客户端未经授权使用此方法检索访问令牌"
static async Task MainAsync()
{
sstageEntities db = new sstageEntities();
//UserCredential credential;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
String serviceAccountEmail =
"xxx.iam.gserviceaccount.com";
var certificate = new X509Certificate2(
AppDomain.CurrentDomain.BaseDirectory +
"xxx-8c7a4169631a.p12",
"notasecret",
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
//string userEmail = "user@domainhere.com.au";
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = "xxx@xxx.com",
Scopes = new[] { "https://mail.google.com/" }
}.FromCertificate(certificate)
);
// Create Gmail API service.
var gmailService = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
}); …Run Code Online (Sandbox Code Playgroud) 按照有关如何执行 G Suite 域范围授权的说明,请参见此处 https://developers.google.com/admin-sdk/directory/v1/guides/delegation 我完成了所有步骤,但现在我是坚持在我的应用程序中实现 SDK 目录服务对象,我在前端使用 Angular 7,后端使用 NodeJs(Firebase 云函数),但此处给出的代码仅支持 Java、Python 和 Go。谁能告诉我如何将其转换为 NodeJS?