c# - Have you used Google's Directory API? -


i'm trying use google directory api library .net maintain email addresses domain. latest library google-admin-directory_v1-rev6-csharp-1.4.0-beta. best , farthest i've gotten far receive 403 error (not authorized access resource/api).

has out there used it? if so, share code, tips, or tricks?

i have used , got success in creating console-application. @ moment i'm trying find way skip copy/paste of authorization code. don't forget turn on api access in apis console. i'll show small sample:

using system; using system.diagnostics; using system.linq; using system.threading.tasks; using system.security.cryptography; using system.security.cryptography.x509certificates;  using dotnetopenauth.oauth2;  using google.apis.authentication.oauth2; using google.apis.authentication.oauth2.dotnetopenauth; using google.apis.samples.helper; using google.apis.services; using google.apis.util; using google.apis.admin.directory_v1; using google.apis.admin.directory_v1.data;    namespace bergstedts.createnewuser {     public class program     {     static void main(string[] args)     {          // display header , initialize sample.         commandline.enableexceptionhandling();         console.writeline("create users in google apps domain!");         console.writeline("by jonas bergstedt 2013");          // user data , store in user object         console.write("email: ");         string userid = console.readline();          console.write("givenname: ");         string givenname = console.readline();          console.write("familyname: ");         string familyname = console.readline();          console.write("password: ");         string password = console.readline();          user newuserbody = new user();         username newusername = new username();         newuserbody.primaryemail = userid;         newusername.givenname = givenname;         newusername.familyname = familyname;         newuserbody.name = newusername;         newuserbody.password = password;          // register authenticator.         var provider = new nativeapplicationclient(googleauthenticationserver.description)             {                 clientidentifier = "<your clientid google apis console>",                 clientsecret = "<your clientsecret google apis console>",             };          var auth = new oauth2authenticator<nativeapplicationclient>(provider, getauthorization);          // create service.         var service = new directoryservice(new baseclientservice.initializer()             {                 authenticator = auth,                 applicationname = "create user",                 apikey = "<your api key google apis console> (not sure if needed)"                          });          user results = service.users.insert(newuserbody).execute();         console.writeline("user :" + results.primaryemail + " created");         console.writeline("press key continue!");         console.readkey();     }     private static iauthorizationstate getauthorization(nativeapplicationclient arg)     {         // auth url:         iauthorizationstate state = new authorizationstate(new[] { directoryservice.scopes.admindirectoryuser.getstringvalue() });         state.callback = new uri(nativeapplicationclient.outofbandcallbackurl);         uri authuri = arg.requestuserauthorization(state);          // request authorization user (by opening browser window):         process.start(authuri.tostring());         console.writeline();         console.write("authorization code: ");         string authcode = console.readline();          // retrieve access token using authorization code:        return arg.processuserauthorization(authcode, state);     } } 

}


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -