HttpError 403 : “Not Authorized to access this resource/api”> when trying to add members to a group










0















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? :)










share|improve this question


























    0















    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? :)










    share|improve this question
























      0












      0








      0








      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? :)










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 10:44









      SLedsaakSLedsaak

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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






          share|improve this answer






















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



            );













            draft saved

            draft discarded


















            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









            0














            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






            share|improve this answer



























              0














              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






              share|improve this answer

























                0












                0








                0







                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






                share|improve this answer













                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 14:31









                abielitaabielita

                9,4522939




                9,4522939





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo