this is the request I need to make (trying to get list of members in a google group):
GET https://admin.googleapis.com/admin/directory/v1/groups/{groupKey}/members
https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/list?apix_params=%7B%22groupKey%22%3A%22devops%40flight-analytics.com%22%2C%22includeDerivedMembership%22%3Atrue%2C%22maxResults%22%3A200%2C%22prettyPrint%22%3Atrue%7D
group key in this case is email for the group eg: [email protected] how can i make it into a python script and get my results.
this is the attempt I was expecting to work.
def make_request(request):
"""
HTTP Cloud Function that makes another HTTP request.
Args:
request (flask.Request): The request object.
<http://flask.pocoo.org/docs/1.0/api/#flask.Request>
Returns:
The response text, or any set of values that can be turned into a
Response object using `make_response`
<http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>.
"""
import requests
# The URL to send the request to
#url = 'https://google.com'
# Process the request
response = requests.get(request)
response.raise_for_status()
print(response)
print(response.text)
print(response.raise_for_status())
print("Success")
return 'Success!'
make_request("https://admin.googleapis.com/admin/directory/v1/groups/[email protected]/members")
But the script fails saying i dont have proper login but i did ran:
gcloud auth login
gcloud auth application-default login
before firing the python script in same shell but end up getting error:
Traceback (most recent call last):
File "/Users/deepak.sandhu/Desktop/test.py", line 55, in <module>
make_request("https://admin.googleapis.com/admin/directory/v1/groups/[email protected]/members")
File "/Users/deepak.sandhu/Desktop/test.py", line 48, in make_request
response.raise_for_status()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://admin.googleapis.com/admin/directory/v1/groups/[email protected]/members
gcloud auth loginauthorizes the CLI (gcloud). Usegcloud auth application-default loginto authorize application credentials.gcloud auth application-default login