Регистрация в Google Classroom Pub / Sub возвращает ошибку аутентификации 403 - PullRequest
0 голосов
/ 11 июня 2019

Я разрабатываю php-приложение с использованием Google Classroom и продолжаю получать «код»: 403, «message»: «В запросе недостаточно областей аутентификации». ошибка.

Вот что я сделал до сих пор, любая помощь будет огромной!

  • Я настроил oauth для своего приложения на использование auth / classroom.push-notifications

  • Я установил classroom-notifications@system.gserviceaccount.com, чтобы иметь роль Pub / Sub Publisher

  • Я настроил паб / подтему

Вот код, который я использую:

$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.

Любая помощь в определении того, что мне не хватает, будет принята с благодарностью!

1 Ответ

0 голосов
/ 12 июня 2019

Я идиот.Хотя я не забывал добавить область push-уведомлений в консоль разработчика 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();
...