Reputation: 11
I want to add members to a google group([email protected]) using the api. The issue is that I only need to use @googlegroups.com as the domain for google group. But seems like google only allow workspace accounts to use api. I even tried creating a workspace account and created a google group ending with @googlegroup inside the workspace account. But seems like we cant even fetch those google groups through api(I included my code below). We are only getting the google groups ending with the domain name ([email protected]). Do you anyone know or tried any workaround to add members to a google group ending with @googlegroups using api ?
Context: Google Play Closed testing needs testers to be in the google group that is added to the play console to test the app. But the issue here is that closed testing is only allowing google groups ending with @googlegroups.com. So google groups created in google workspace cannot be used to add in the closed testing.
If thats not possible can we link a workspace google group with an external google group ? so that all members of workspace google group comes under external google group ?
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors
import HttpError
def list_google_groups(customer_id='my_customer'):
CREDENTIALS_FILE = 'credentials.json'
SCOPES = ['https://www.googleapis.com/auth/admin.directory.group']
try:
credentials = service_account.Credentials.from_service_account_file(
CREDENTIALS_FILE,
scopes=SCOPES
)
delegated_credentials = credentials.with_subject('[email protected]')
# Build the API service
service = build('admin', 'directory_v1', credentials=delegated_credentials)
groups = []
page_token = None
while True:
try:
# List all groups in the domain
results = service.groups().list(
customer=customer_id,
pageToken=page_token,
orderBy='email' # Sort by email address
).execute()
current_groups = results.get('groups', [])
# Process each group
for group in current_groups:
group_info = {
'email': group['email'],
'name': group.get('name', 'N/A'),
'description': group.get('description', 'N/A'),
'id': group['id'],
'directMembersCount': group.get('directMembersCount', 'N/A'),
'created': group.get('createTime', 'N/A')
}
groups.append(group_info)
# Print group details
print(f"\nGroup: {group_info['name']}")
print(f"Email: {group_info['email']}")
print(f"Description: {group_info['description']}")
print(f"Members Count: {group_info['directMembersCount']}")
print("-" * 50)
# Check if there are more pages
page_token = results.get('nextPageToken')
if not page_token:
break
except HttpError as error:
print(f'An error occurred: {error}')
break
return groups
except Exception as e:
print(f"An error occurred: {str(e)}")
raise
if __name__ == "__main__":
print("Fetching all Google Groups...")
groups = list_google_groups()
Upvotes: 0
Views: 18