0

I tried authenticating with Google Admin Api-sdk But We get some file missings error which should be created by the Dlls, we are using. Even after adding all the recommended dlls after going through many article for the same, I din get over to this. Here is the code im using.

 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();
        }
    }
}

I am using this code for new user provisioning but Google.Apis.Admin.Directory.directory_v1.cs not found while debugging due to this authentication got failed. Please anybody let me know to to get Google.Apis.Admin.Directory.directory_v1.cs file. As much i know i have already added all the dlls added. The Namespaces i am using are as follows:

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;
OyeHarish
  • 320
  • 2
  • 8

2 Answers2

0

As per the documentation, you need to download an extra NuGet package for each API you want to use. These packages contain the generated code for that particular API.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
0

thanks all for replying,

I managed to run it successfully, I had all the reference, Code was upto the mark as well. The Only problem was with the admin setting there in the google admin panel.

I manage to correct them as per my request to google API's and it worked fine.

OyeHarish
  • 320
  • 2
  • 8