Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

from google.auth import credentials
from google.auth.transport.requests import Request
from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/admin.directory.group.readonly',
          'https://www.googleapis.com/auth/admin.directory.group.member.readonly',
          'https://www.googleapis.com/auth/admin.directory.group.member',
          'https://www.googleapis.com/auth/admin.directory.group']

# Path to your service account JSON key file
SERVICE_ACCOUNT_FILE = 'key.json'

# Create credentials object
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)

# Refresh the credentials to obtain an access token
credentials.refresh(Request())

# Get the access token
access_token = credentials.token

print(access_token)
import requests

url = "https://admin.googleapis.com/admin/directory/v1/groups/demo@protecto.io/members"

access_token ="nfkaefiuagefhiu........skjgsgf"
headers = {"Authorization": f"Bearer {access_token}"}

response = requests.get(url, headers=headers)

# Print the response
print(response.json())

created an access token with the scopes used it to make get call. im getting this error
{'error': {'code': 403, 'message': 'Not Authorized to access this resource/api', 'errors': [{'message': 'Not Authorized to access this resource/api', 'domain': 'global', 'reason': 'forbidden'}]}}

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.