I am trying to get all assignments from a users classes and for some reason, it gives me this error:
Traceback (most recent call last):
File "C:/Users/oscar/Desktop/Development/Python/main.py", line 50, in <module>
main()
File "C:/Users/oscar/Desktop/Development/Python/main.py", line 29, in main
creds = flow.run_local_server(port=0)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\google_auth_oauthlib\flow.py", line 474, in run_local_server
self.fetch_token(authorization_response=authorization_response)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\google_auth_oauthlib\flow.py", line 288, in fetch_token
return self.oauth2session.fetch_token(self.client_config["token_uri"], **kwargs)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\requests_oauthlib\oauth2_session.py", line 360, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 421, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 431, in parse_token_response
validate_token_parameters(params)
File "C:\Users\oscar\Desktop\Development\Python\venv\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 461, in validate_token_parameters
raise w
Warning: Scope has changed from "https://www.googleapis.com/auth/classroom.courses.readonly https://www.googleapis.com/auth/classroom.coursework.me.readonly" to "https://www.googleapis.com/auth/classroom.student-submissions.me.readonly https://www.googleapis.com/auth/classroom.courses.readonly".
Process finished with exit code 1
Here is my code:
from __future__ import print_function
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly', 'https://www.googleapis.com/auth/classroom.coursework.me.readonly']
def main():
"""Shows basic usage of the Classroom API.
Prints the names of the first 10 courses the user has access to.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
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(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('classroom', 'v1', credentials=creds)
# Call the Classroom API
results = service.courses().list(pageSize=10).execute()
courses = results.get('courses', [])
if not courses:
print('No courses found.')
else:
for course in courses:
print(course['name'])
course_id = course['id']
results1 = service.courses().courseWork().list(courseId=course_id).execute()
print(results1)
if __name__ == '__main__':
main()
I think this is happening because of the second scope but it's the one they say to use on the official API so Idk why its giving me an error. Any help would be appreciated.