请求的客户未被授权 [英] Requested client not authorized

查看:28
本文介绍了请求的客户未被授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 google 服务帐户 从我的域中获取 google 用户.

I am trying to get google users from my domain using google service account.

但是会报错

Error:"access_denied", Description:"Requested client not authorized.", Uri:""

我的代码

X509Certificate2 certificate = new X509Certificate2(key_path,
                         "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer("publickey.gserviceaccount.com")
           {   Scopes = scopes,
               User = "admin@domain.com"
           }.FromCertificate(certificate));

var service = new DirectoryService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "appname",
        });

service.Users.List().Domain = "domain.com";
Users results = service.Users.List().Execute();

提前致谢

推荐答案

服务帐户电子邮件地址需要具有访问域的权限.获取电子邮件并将其添加为用户,只要它可以阅读就足够了.

The service account email address needs to have access the domain. Take the email and add it as a user just enough access that it can read should be good.

你也是为了发帖而改变这个的吗?

Also did you change this for posting?

"publickey.gserviceaccount.com"

服务帐户电子邮件看起来更像这样:

A service account email looks more like this:

539621478854-imkdv94bgujcom228h3ea33kmkoefhil@developer.gserviceaccount.com

这篇关于请求的客户未被授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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