Google课堂403:“来电者没有权限”错误

时间:2018-01-31 21:32:57

标签: ios swift google-api google-classroom

我正在尝试使用Google Classroom Pub / Sub通知注册用户,但我一直收到403: "The caller does not have permission"错误。我已在Google管理控制台中使用ID "gclassroom"正确设置了发布/订阅主题,因此我的主题ID与"projects/myappid-12345/topics/gclassroom"一致。我还在此主题下设置了classroom-notifications@system.gserviceaccount.com作为发布/订阅发布者。

我的代码:

private let scopes = [kGTLRAuthScopeClassroomCoursesReadonly, kGTLRAuthScopeClassroomCourseworkMeReadonly, kGTLRAuthScopeClassroomPushNotifications, kGTLRAuthScopeClassroomRostersReadonly]
private let service = GTLRClassroomService()

@IBAction func signInButtonTapped(_ sender: Any) {

    // Configure Google Sign-in.
    GIDSignIn.sharedInstance().delegate = self
    GIDSignIn.sharedInstance().uiDelegate = self
    GIDSignIn.sharedInstance().scopes = scopes

    GIDSignIn.sharedInstance().signIn()
}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
          withError error: Error!) {

    self.service.authorizer = user.authentication.fetcherAuthorizer()

    let feed = GTLRClassroom_Feed()
    feed.feedType = kGTLRClassroom_Feed_FeedType_DomainRosterChanges

    let topic = GTLRClassroom_CloudPubsubTopic()
    topic.topicName = "projects/myappid-12345/topics/gclassroom"

    let registration = GTLRClassroom_Registration()
    registration.cloudPubsubTopic = topic
    registration.feed = feed
    let query = GTLRClassroomQuery_RegistrationsCreate.query(withObject: registration)
    service.executeQuery(query,
                         delegate: self,
                         didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:)))
}

当我运行它时,我可以使用我的Google Classroom帐户登录,但它会立即抛出此错误:

["GTLRStructuredError": GTLRErrorObject 0x604000a566b0: {errors:[1] message:"The caller does not have permission" code:403 status:"PERMISSION_DENIED"}, "NSLocalizedDescription": The caller does not have permission]

如何修复此代码并让用户注册?感谢。

0 个答案:

没有答案