缺少范围错误:google.auth.exceptions.RefreshError

Jus*_*te- 5 python google-api google-classroom

我正在尝试构建一个 Google Classroom 扩展,让用户可以控制何时接收“工作即将到期”通知。但是,当令牌刷新时,我收到此错误:“引发异常。RefreshError(google.auth.exceptions.RefreshError:授权服务器未授予所有请求的范围,缺少范围https://www.googleapis.com/auth /classroom.coursework.me.readonly。”

所使用的代码直接来自谷歌教室的谷歌授权页面

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())
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,错误的范围已经在我的项目范围列表中。我发现解决此问题的唯一方法是删除令牌文件,并在每次令牌过期时登录。我检查了课堂 api 文档和堆栈溢出,但找不到解决方案。任何帮助将不胜感激。