Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 请求没有足够的课堂通知身份验证作用域_Python_Api_Google Classroom - Fatal编程技术网

Python 请求没有足够的课堂通知身份验证作用域

Python 请求没有足够的课堂通知身份验证作用域,python,api,google-classroom,Python,Api,Google Classroom,我正在使用PythonAPI从教室获取公告 我的代码: from __future__ import print_function import pickle import os.path from os import getcwd from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.request

我正在使用PythonAPI从教室获取公告

我的代码:

from __future__ import print_function
import pickle
import os.path
from os import getcwd
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

class ClassRoom:
    # If modifying these scopes, delete the file token.pickle.
    def announcements_list(self):
        self.SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly', 
                       'https://www.googleapis.com/auth/classroom.announcements.readonly']
        """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(
                    'credentials.json', self.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
        results = service.courses().list(pageSize=10).execute()
        courses = results.get('courses', [])
        announcements = []
        for course in course:
            announcements += service.courses().announcements().list(courseId=course["id"], 
                             pageSize=1).execute().get("annoucements")
        return announcements

cs = ClassRoom()
print(cs.announcements_list())
但是脚本正在生成httperror403error,类似于 “请求的身份验证作用域不足。”。详细信息:“请求的身份验证作用域不足。”


如何解决此问题?

我也遇到同样的问题,请从文件夹中删除token.pickle并再次执行。更改您的作用域后,它应该可以工作

您是否删除了您的令牌文件以触发新的授权流?是,但没有帮助您是教师、学生还是管理员?您是否具有访问指定课程及其公告的其他权限?你测试过这个功能吗?