问题
The documentation is a little unclear on this. Can I actually do this? The only examples I've seen so far are from the Google documentation that show it using the GoogleAuthorizationCodeFlow class to gain authorization. I've seen a few examples of using the Service Account to update and retrieve a list of users, but nothing for creating. Is this possible? If so, does anyone know of any examples floating around? I can't seem to find anything that addresses it.
回答1:
You can follow the steps outlined in the following API docs page to create the service account and perform a domain wide delegation of authority, please bear in mind you need the email address of a domain administrator which the service account can act on their behalf:
https://developers.google.com/admin-sdk/directory/v1/guides/delegation
The page includes a Java example of how to instantiate a com.google.api.services.admin.directory.Directory object using the service account and private key created on the Google Developers Console. Then use the example I've provided in this answer to create the users:
Create gmail account for a domain using Google Admin SDK Directory API in Java
来源:https://stackoverflow.com/questions/26238087/create-users-using-service-account-with-google-admin-sdk