How can I get my Google Groups via API? I am NOT admin

650 Views Asked by At

I want to get all my groups but I am not an admin

I know how to fetch groups if I am admin. But if not - I don't understand. Also I can see its via website

My steps:

  1. I do auth with Google and with scope
[
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/groups",
]
  1. I fetch groups by GET. Url: "https://admin.googleapis.com/admin/directory/v1/groups?domain=konstructly.com"

  2. I get the next problem:

{
  "error": {
    "code": 403,
    "message": "Not Authorized to access this resource/api",
    "errors": [
      {
        "message": "Not Authorized to access this resource/api",
        "domain": "global",
        "reason": "forbidden"
      }
    ]
  }
}

My question

How can I get my Google Groups via Google API?

I tried:

  1. Auth with scope
[
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/groups",
]
  1. GET "https://admin.googleapis.com/admin/directory/v1/groups?domain=konstructly.com"

Expectation: List of my groups

Actual result:

{
  "error": {
    "code": 403,
    "message": "Not Authorized to access this resource/api",
    "errors": [
      {
        "message": "Not Authorized to access this resource/api",
        "domain": "global",
        "reason": "forbidden"
      }
    ]
  }
}
1

There are 1 best solutions below

0
Wicket On

Instead of using the Google Workspace Admin SDK, use the Groups Service from Google Apps Script, more specifically GroupsApp.getGroups()