我正在使用Google Classroom开发php应用程序,并不断获取“代码”:403,“消息”:“请求的身份验证范围不足。”错误。
这是我到目前为止所做的,任何帮助都是巨大的!
我已设置我的应用程序oauth权限以使用auth / classroom.push-notifications
我将'classroom-notifications@system.gserviceaccount.com'设置为具有发布/订阅发布者角色
我已经设置了发布/订阅主题
这是我正在使用的代码:
$google_course_id = '123456';
$topic_name = 'projects/my-app-name/topics/TopicName';
$feed_type = 'COURSE_WORK_CHANGES';
$user = User::find(2); // User who has authorized via OAuth and accepted all permissions
$client = new Google_Client();
$client->setAccessToken($user->get_google_social_token());
$classroom = new Google_Service_Classroom($client);
$pub_sub = new Google_Service_Classroom_CloudPubsubTopic();
$pub_sub->setTopicName($topic_name);
$work_changes_info = new Google_Service_Classroom_CourseWorkChangesInfo();
$work_changes_info->setCourseId($google_course_id);
$feed = new Google_Service_Classroom_Feed();
$feed->setCourseWorkChangesInfo($work_changes_info);
$feed->setFeedType($feed_type);
$registration = new Google_Service_Classroom_Registration();
$registration->setCloudPubsubTopic($pub_sub);
$registration->setFeed($feed);
$classroom->registrations->create($registration);
不幸的是,我一直收到403错误。
在确定我所缺少的方面提供的任何帮助将不胜感激!
答案 0 :(得分:0)
我是个白痴。当我记得将推送通知范围添加到我的Google开发人员控制台时,我忘记将它们添加到Oauth链接代码中。将其添加到底部似乎已解决了该问题!
return Socialite::driver('google')
->scopes(['https://www.googleapis.com/auth/classroom.courses.readonly',
'https://www.googleapis.com/auth/classroom.rosters.readonly',
'https://www.googleapis.com/auth/classroom.coursework.students.readonly',
'https://www.googleapis.com/auth/classroom.guardianlinks.students.readonly',
'https://www.googleapis.com/auth/classroom.profile.emails',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/classroom.push-notifications',
])
->with(['access_type' => 'offline', 'prompt' => 'consent select_account'])
->redirect();