2

I'm writing a script from Google Sheets to handle users in my domain. In particular, at this line of code:

var user = AdminDirectory.Users.get(userEmail);

I get the error:

Not Authorized to access this resource/api

This is an answer to a similar question, but doesn't work. I check that Admin SDK service is enabled and active and the script runs as SuperAdmin user.

How can I authorize my script to access Admin SDK API?

1 Answers1

1

Either one of the services you are attempting to access is disabled, the script user does not have privileges to access the API, or the admin account you are using has not been logged in manually to accept the terms of service agreement.

Google Admin SDK must be enabled on your domain before you can use it.

From the Enabling advanced services:

To use an advanced Google service, follow these instructions:

In the script editor, select Resources > Advanced Google services....

In the Advanced Google Service dialog that appears, click the on/off switch next to the service you want to use.

Click OK in the dialog.


Make sure your service account has domain wide authority:

Go to your G Suite domain’s Admin console.

Select Security from the list of controls. If you don't see Security listed, select More controls from the gray bar at the bottom of the page, then select Security from the list of controls.

Select Advanced settings from the list of options.

Select Manage API client access in the Authentication section.

In the Client name field, enter the client ID obtained from the service account >creation steps above.

In the One or More API Scopes field enter the scopes required for your application (for a list of possible scopes, see Authorize requests).

Click the Authorize button.


You must log into the system using the credentials in a web browser to accept the terms of service before an account can be used to administer the domain.

Following these three items should resolve your issue.

Community
  • 1
  • 1
  • Google Admin SDK is enabled. I've created a service account, but it requires an OAuth consent screen which I cannot configure. – Fabio Lucchini Aug 01 '19 at 07:34