Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
victor-rayan opened this issue · comments
Summary
-
I'm trying this method https://developers.google.com/classroom/reference/rest/v1/courses.courseWork/list
-
The python code below to Method: courses.students.list https://developers.google.com/classroom/reference/rest/v1/courses.students/list using the same credentials works good
Expected Behavior
a list of course work that the requester is permitted to view.
{
"courseWork": [
{
object (CourseWork)
}
],
"nextPageToken": string
}
Actual Behavior
Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
Steps to Reproduce the Problem
SCOPES = [
'https://www.googleapis.com/auth/classroom.coursework.students.readonly',
'https://www.googleapis.com/auth/classroom.coursework.me.readonly',
'https://www.googleapis.com/auth/classroom.coursework.students',
'https://www.googleapis.com/auth/classroom.coursework.me'
]
def listcourseWork(idcourse):
creds = None
try:
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'client_secret.json', SCOPES)
creds = flow.run_local_server(port=0)
print(creds)
# Save the credentials for the next run
try:
with open('token.json', 'w') as token:
token.write(creds.to_json())
except Exception as error:
print(error)
except Exception as error:
print(error)
try:
service = build('classroom', 'v1', credentials=creds)
studentsFormated = []
# Call the Classroom API
results = service.courses().courseWork().list(courseId = idcourse).execute()
print(results)
except Exception as error:
print(error)
if __name__ == '__main__':
listcourseWork('525987525315')
Specifications
- Python version (`python --3.10)
- OS (Windows)
SOLVED.
SCOPES = [
'https://www.googleapis.com/auth/classroom.coursework.students'
]