首页 > 解决方案 > Google Classroom API 和 Swift:交作业时出错

问题描述

我正在用 Swift 和 Xcode 构建一个应用程序。为此,我使用的是 Google Classroom API。尝试提交家庭作业时,我收到此错误:“@ProjectPermissionDenied 不允许开发者控制台项目提出此请求。”

查看其他 Stack Overflow 帖子,我发现这是因为作业是由另一个开发者控制台项目创建的,我无权将它们上交。但是,有什么方法可以让我上交任务?

这是 App Delegate 中的代码:

func turnInHomeworkAssignment(courseId: String, courseWorkId : String, studentSubmissionId : String, onCompleted : @escaping(Error?) -> ()) {
    if self.service.authorizer != nil {
        let turnInObject = GTLRClassroom_TurnInStudentSubmissionRequest.init()
        let turnInAssignment = GTLRClassroomQuery_CoursesCourseWorkStudentSubmissionsTurnIn.query(withObject: turnInObject, courseId: courseId, courseWorkId: courseWorkId, identifier: studentSubmissionId)

        self.service.executeQuery(turnInAssignment) { (ticket, results, error) in
            onCompleted(error)
        }
    }
}

当按下一个按钮来提交作业时,它将调用以下代码:

let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.turnInHomeworkAssignment(courseId: courseID, courseWorkId : courseWorkID, studentSubmissionId : studentSubmissionID) { (error) in
        if error != nil {
            print ("Error turning in Homework: \(String(describing: error?.localizedDescription))")
            return
        }

    }

非常感谢你,罗莎莉

标签: swiftxcodeapigoogle-apigoogle-classroom

解决方案


推荐阅读