HttpError 403 : “Not Authorized to access this resource/api”> when trying to add members to a group
Here is my code:
def addUsersToGroup(users,group):#users is a list of emails.
SCOPES1 = 'https://www.googleapis.com/auth/admin.directory.group'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES1)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
groupbody={'email':group}
add_group = service.groups().insert(body=groupbody).execute() #making the group
for user in users:
emailbody = {'email':user}
group_add=service.members().insert(groupKey=groupbody, body=emailbody).execute()
When running this I am allowed to create a group but not add members to it. I have enabled domain-wide access the scope https://www.googleapis.com/auth/admin.directory.group for my google admin account.
Here is the errorcode :
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requestinghttps://www.googleapis.com/admin/directory/v1/groups/%7B%27email%27%3A%20%
27alfabetet%40ntnui.no%27%7D/members?alt=json returned "Not Authorized
to access this resource/api">
Help? :)
google-admin-sdk
add a comment |
Here is my code:
def addUsersToGroup(users,group):#users is a list of emails.
SCOPES1 = 'https://www.googleapis.com/auth/admin.directory.group'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES1)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
groupbody={'email':group}
add_group = service.groups().insert(body=groupbody).execute() #making the group
for user in users:
emailbody = {'email':user}
group_add=service.members().insert(groupKey=groupbody, body=emailbody).execute()
When running this I am allowed to create a group but not add members to it. I have enabled domain-wide access the scope https://www.googleapis.com/auth/admin.directory.group for my google admin account.
Here is the errorcode :
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requestinghttps://www.googleapis.com/admin/directory/v1/groups/%7B%27email%27%3A%20%
27alfabetet%40ntnui.no%27%7D/members?alt=json returned "Not Authorized
to access this resource/api">
Help? :)
google-admin-sdk
add a comment |
Here is my code:
def addUsersToGroup(users,group):#users is a list of emails.
SCOPES1 = 'https://www.googleapis.com/auth/admin.directory.group'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES1)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
groupbody={'email':group}
add_group = service.groups().insert(body=groupbody).execute() #making the group
for user in users:
emailbody = {'email':user}
group_add=service.members().insert(groupKey=groupbody, body=emailbody).execute()
When running this I am allowed to create a group but not add members to it. I have enabled domain-wide access the scope https://www.googleapis.com/auth/admin.directory.group for my google admin account.
Here is the errorcode :
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requestinghttps://www.googleapis.com/admin/directory/v1/groups/%7B%27email%27%3A%20%
27alfabetet%40ntnui.no%27%7D/members?alt=json returned "Not Authorized
to access this resource/api">
Help? :)
google-admin-sdk
Here is my code:
def addUsersToGroup(users,group):#users is a list of emails.
SCOPES1 = 'https://www.googleapis.com/auth/admin.directory.group'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES1)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
groupbody={'email':group}
add_group = service.groups().insert(body=groupbody).execute() #making the group
for user in users:
emailbody = {'email':user}
group_add=service.members().insert(groupKey=groupbody, body=emailbody).execute()
When running this I am allowed to create a group but not add members to it. I have enabled domain-wide access the scope https://www.googleapis.com/auth/admin.directory.group for my google admin account.
Here is the errorcode :
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requestinghttps://www.googleapis.com/admin/directory/v1/groups/%7B%27email%27%3A%20%
27alfabetet%40ntnui.no%27%7D/members?alt=json returned "Not Authorized
to access this resource/api">
Help? :)
google-admin-sdk
google-admin-sdk
asked Nov 13 '18 at 10:44
SLedsaakSLedsaak
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Based from this thread, this might be a permissions issue.
Seems that this issue is related to this topic here:
Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
You need to pass account email with admin permissions into credentials
like this:
credentials = SignedJwtAssertionCredentials('CLIENT_EMAIL',
key, scope='https://www.googleapis.com/auth/admin.directory.user', sub='superadmin@domain.com')
This process is now documented at: https://developers.google.com/admin-sdk/directory/v1/guides/delegation
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279261%2fhttperror-403-not-authorized-to-access-this-resource-api-when-trying-to-add%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Based from this thread, this might be a permissions issue.
Seems that this issue is related to this topic here:
Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
You need to pass account email with admin permissions into credentials
like this:
credentials = SignedJwtAssertionCredentials('CLIENT_EMAIL',
key, scope='https://www.googleapis.com/auth/admin.directory.user', sub='superadmin@domain.com')
This process is now documented at: https://developers.google.com/admin-sdk/directory/v1/guides/delegation
add a comment |
Based from this thread, this might be a permissions issue.
Seems that this issue is related to this topic here:
Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
You need to pass account email with admin permissions into credentials
like this:
credentials = SignedJwtAssertionCredentials('CLIENT_EMAIL',
key, scope='https://www.googleapis.com/auth/admin.directory.user', sub='superadmin@domain.com')
This process is now documented at: https://developers.google.com/admin-sdk/directory/v1/guides/delegation
add a comment |
Based from this thread, this might be a permissions issue.
Seems that this issue is related to this topic here:
Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
You need to pass account email with admin permissions into credentials
like this:
credentials = SignedJwtAssertionCredentials('CLIENT_EMAIL',
key, scope='https://www.googleapis.com/auth/admin.directory.user', sub='superadmin@domain.com')
This process is now documented at: https://developers.google.com/admin-sdk/directory/v1/guides/delegation
Based from this thread, this might be a permissions issue.
Seems that this issue is related to this topic here:
Received error "Not Authorized to access this resource/api" when trying to use Google Directory API and Service Account Authentication
You need to pass account email with admin permissions into credentials
like this:
credentials = SignedJwtAssertionCredentials('CLIENT_EMAIL',
key, scope='https://www.googleapis.com/auth/admin.directory.user', sub='superadmin@domain.com')
This process is now documented at: https://developers.google.com/admin-sdk/directory/v1/guides/delegation
answered Nov 13 '18 at 14:31
abielitaabielita
9,3012839
9,3012839
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279261%2fhttperror-403-not-authorized-to-access-this-resource-api-when-trying-to-add%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown