从GoogleClassroomApi[403]Python检索类工作
我正试图从谷歌课堂API中检索每门课程的课堂作业。我已经成功地获得了所有课程,但我仍停留在课程作业上: 这是我正在使用的代码:从GoogleClassroomApi[403]Python检索类工作,python,google-classroom,Python,Google Classroom,我正试图从谷歌课堂API中检索每门课程的课堂作业。我已经成功地获得了所有课程,但我仍停留在课程作业上: 这是我正在使用的代码: from __future__ import print_function import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.tra
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/classroom.coursework.students.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.pickle 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.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# 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(
r"\test\credentials.json", SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('classroom', 'v1', credentials=creds)
# Call the Classroom API
course_work_results = service.courses().courseWork().list(courseId="167997334462").execute()
[...]
if __name__ == '__main__':
main()
我已使用管理员帐户生成凭据;我还尝试了几种不同的作用域,但都是相同的错误
你们能帮帮我吗
我正在使用Python 3.9
谢谢,
亚历山大
https://www.googleapis.com/auth/classroom.coursework.students.readonly
我想你是个学生
https://www.googleapis.com/auth/classroom.coursework.me.readonly