0

我尝试使用Google Admin API-sdk进行身份验证但是,我们收到了一些应由Dll创建的文件错误错误,我们正在使用。 即使在阅读了许多文章之后添加了所有推荐的dll之后,我仍然会接受这一点。这是我使用的代码。使用Google Admin SDK的Google用户帐户c# - Google.Apis.Admin.Directory.directory_v1.cs找不到

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 = "[email protected]"; 
       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 = "[email protected]"; 
      newusername.GivenName = "Harsh"; 
      newusername.FamilyName = "Sharma"; 
      newuserbody.Name = newusername; 
      newuserbody.Password = "[email protected]"; 
      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; 
+0

这个https://code.google.com/p/google-api-dotnet-client/source/browse/Services/Google.Apis.Admin.directory_v1.cs?repo=samples&r=498cff20b5880f3fbebd1aeac9acafda4d1c3ce3也许? – Emily 2014-10-28 23:09:25

+0

你有没有把所有的参考文献设置为复制本地真实? – DaImTo 2014-10-29 08:30:07

回答

0

感谢所有回答道:

我设法成功地运行它,我把所有的引用,代码是高达标记为好。 唯一的问题是在谷歌管理面板中的管理设置。

我设法纠正它们,根据我对谷歌API的要求,它工作得很好。

0

As per the documentation,你需要下载额外的NuGet包为您要使用的每个API。这些软件包包含为特定API生成的代码。