我正在尝试设置c#代码来管理我们的Google域名.
每当我调用service.Users.List()或DirectoryService api中的任何其他方法时,我都会收到此错误.
Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]
Run Code Online (Sandbox Code Playgroud)
我按照OAuth设置上的所有说明进行操作.我使用的帐户是域管理员.
当我使用GAM.exe执行相同的操作时,我使用的客户端密码文件工作正常.这让我相信我在代码中做错了.
下面是我查询用户的代码,有什么我遗漏的吗?
static void Main(string[] args)
{
var applicationName = "App Project Name";
var userName = "admin@domain.com";
var clientID = "clientIDfromAPIcredentialpageonconsole.developers.google.com";
UserCredential credential;
using (var stream = new FileStream("C:\\gam\\client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { DirectoryService.Scope.AdminDirectoryOrgunit, DirectoryService.Scope.AdminDirectoryUser },
userName,
CancellationToken.None, null).Result;
}
var service = new DirectoryService(new BaseClientService.Initializer()
{
ApplicationName = applicationName,
HttpClientInitializer = credential
});
var list = …Run Code Online (Sandbox Code Playgroud) 将请求从www.mysite.com重定向到www.mysite.com/swagger的正确方法是什么?
我设置了一个索引控制器装饰路线(""),它的工作原理,但看起来像一个Kludge.我假设应该有一种方法在Startup.cs中的MVC路由中指定它,我只是想不出来.
// kludge code, how do I do this in app.UseMvc(route => route.MapRoute...
[ApiExplorerSettings(IgnoreApi = true)]
[Route("")]
public class IndexController : Controller
{
public ActionResult Index()
{
return Redirect("/swagger");
}
}
Run Code Online (Sandbox Code Playgroud)