使用谷歌管理SDK c#的谷歌用户设置--找不到Google.Apis.Admin.Directory.Director



我尝试使用Google Admin Api sdk进行身份验证,但我们遇到了一些文件丢失错误,应该由我们正在使用的Dlls创建。即使在浏览了许多相同的文章后添加了所有推荐的dll,我也无法理解这一点。这是我使用的代码。

 protected void Page_Load(object sender, EventArgs e)
            {
                const string serviceAccountEmail = "<id>@developer.gserviceaccount.com";
                const string serviceAccountCertPath = @"E:Test.p12";
                const string serviceAccountCertPassword = "notasecret";
                const string userEmail = "admin@mydomain.com";
                var certificate = new X509Certificate2(serviceAccountCertPath, serviceAccountCertPassword, X509KeyStorageFlags.Exportable);
                ServiceAccountCredential credential = new ServiceAccountCredential(
               new ServiceAccountCredential.Initializer(serviceAccountEmail)
               {
                   Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser },
                   User = userEmail

               }.FromCertificate(certificate));
            var service = new DirectoryService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "User Provisioning",
            });
            User newuserbody = new User();
            UserName newusername = new UserName();
            newuserbody.PrimaryEmail = "Harsh@test.com";
            newusername.GivenName = "Harsh";
            newusername.FamilyName = "Sharma";
            newuserbody.Name = newusername;
            newuserbody.Password = "test@123";
            User results = service.Users.Insert(newuserbody).Execute();
        }
    }
}

我正在使用此代码进行新用户设置,但由于此身份验证失败,在调试时找不到Google.Apis.Admin.Directory.Directory_v1.cs。请任何人通知我获取Google.Apis.Admin.Directory.Directory_v1.cs文件。据我所知,我已经添加了所有添加的dll。我使用的命名空间如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Google.Apis.Admin.Directory.directory_v1;
using Google.Apis.Admin.Directory.directory_v1.Data;
using DotNetOpenAuth.GoogleOAuth2;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using Google.Apis.Auth.OAuth2.Requests;
using Google.Apis.Auth.OAuth2.Responses;

根据文档,您需要为要使用的每个API下载一个额外的NuGet包。这些包包含为特定API生成的代码。

感谢所有回复,

我成功地运行了它,我有所有的参考,代码也很到位。唯一的问题是谷歌管理面板中的管理设置。

我设法根据我对谷歌API的请求更正了它们,效果很好。

相关内容

最新更新