Google Clas-s-room Pub/Sub 注册返回 403 身份验证错误
Posted
技术标签:
【中文标题】Google Clas-s-room Pub/Sub 注册返回 403 身份验证错误【英文标题】:Google Clas-s-room Pub/Sub registration returning 403 authentication error 【发布时间】:2019-10-26 08:08:28 【问题描述】:我正在使用 Google Clas-s-room 开发一个 php 应用程序,并且不断收到“代码”:403,“消息”:“请求的身份验证范围不足。”错误。
这是我到目前为止所做的,任何帮助都会非常棒!
我已设置我的应用 oauth 权限以使用 auth/clas-s-room.push-notifications
我已将“clas-s-room-notifications@system.gserviceaccount.com”设置为具有 Pub/Sub Publisher 角色
我已设置 Pub/Sub 主题
这是我正在使用的代码:
$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());
$clas-s-room = new Google_Service_Clas-s-room($client);
$pub_sub = new Google_Service_Clas-s-room_CloudPubsubTopic();
$pub_sub->setTopicName($topic_name);
$work_changes_info = new Google_Service_Clas-s-room_CourseWorkChangesInfo();
$work_changes_info->setCourseId($google_course_id);
$feed = new Google_Service_Clas-s-room_Feed();
$feed->setCourseWorkChangesInfo($work_changes_info);
$feed->setFeedType($feed_type);
$registration = new Google_Service_Clas-s-room_Registration();
$registration->setCloudPubsubTopic($pub_sub);
$registration->setFeed($feed);
$clas-s-room->registrations->create($registration);
很遗憾,我不断收到 403 错误。
我们将不胜感激任何帮助确定我所缺少的东西!
【问题讨论】:
您会遇到“PERMISSION_DENIED”问题之一吗?developers.google.com/clas-s-room/reference/rest/v1/registrations/… 可能是这样,但在这种情况下,我认为我不会收到“身份验证范围不足”错误。 【参考方案1】:我是个白痴。虽然我记得将推送通知范围添加到我的谷歌开发者控制台,但我忘记将它们添加到 Oauth 链接代码中。将其添加到底部似乎已经解决了问题!
return Socialite::driver('google')
->scopes(['https://www.googleapis.com/auth/clas-s-room.courses.readonly',
'https://www.googleapis.com/auth/clas-s-room.rosters.readonly',
'https://www.googleapis.com/auth/clas-s-room.coursework.students.readonly',
'https://www.googleapis.com/auth/clas-s-room.guardianlinks.students.readonly',
'https://www.googleapis.com/auth/clas-s-room.profile.emails',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/clas-s-room.push-notifications',
])
->with(['access_type' => 'offline', 'prompt' => 'consent select_account'])
->redirect();
【讨论】:
以上是关于Google Clas-s-room Pub/Sub 注册返回 403 身份验证错误的主要内容,如果未能解决你的问题,请参考以下文章
Google Clas-s-room API 列出没有注册码的课程?
(403) 请求的身份验证范围不足 - OAuth 范围 Google Clas-s-room API
如何使用 PHP 从 Google Clas-s-room 课程列表中过滤课程对象字段