Google教室API与swift的集成
我想将我的iOS应用程序与swift上的Google教室链接。我目前的目标是能够得到一份我所学的所有课程的清单 这是我目前使用的代码Google教室API与swift的集成,swift,rest,google-api,google-classroom,Swift,Rest,Google Api,Google Classroom,我想将我的iOS应用程序与swift上的Google教室链接。我目前的目标是能够得到一份我所学的所有课程的清单 这是我目前使用的代码 func googleClassroomList() { //let sharedInstance = GIDSignIn.sharedInstance() //let handler = sharedInstance googleClassroomService.apiKey
func googleClassroomList() {
//let sharedInstance = GIDSignIn.sharedInstance()
//let handler = sharedInstance
googleClassroomService.apiKey = "AIzaSyBOGamjhRuu45T2jT7Qa3LmtntSwgIxeqo"
let query = GTLRClassroomQuery_CoursesList.query()
query.pageSize = 1000
let classQuery = googleClassroomService.executeQuery(query, completionHandler: { ticket , fileList, error in
if error != nil {
let message = "Error: \(error?.localizedDescription ?? "")"
print(message)
} else {
if let list = fileList as? GTLRClassroomQuery_CoursesList {
self.fileList = list
print("List: \(list)")
}
else {
print("Error: response is not a file list")
}
}
}
)
}
以下是错误消息:
Error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
我不明白我把OAuth访问令牌附加到哪里,我试着把它放在apiKey下,但我真的不明白我应该做什么。作为参考,我使用这个auth范围。"https://www.googleapis.com/auth/classroom.courses“首先,您必须使用谷歌登录,谷歌将为您管理OAuth 2.0令牌 这里有说明: 另外,请确保在实际登录时设置service.authorizer属性:
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
guard let user = user else {
return
}
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.setLoggedOut(loggedOut: false)
self.myClassroom.service.authorizer = user.authentication.fetcherAuthorizer()
self.showClassroomClasses()
}
首先,您必须使用Google登录,Google将为您管理OAuth 2.0令牌 这里有说明: 另外,请确保在实际登录时设置service.authorizer属性:
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
guard let user = user else {
return
}
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.setLoggedOut(loggedOut: false)
self.myClassroom.service.authorizer = user.authentication.fetcherAuthorizer()
self.showClassroomClasses()
}
我已经实现了谷歌登录,我可以使用这个谷歌驱动器选择器访问谷歌驱动器[并且我在进入我的应用程序时会通过登录屏幕。你是否也设置了googleClassroomService.authorizer=user.authentication.FetcheraAuthorizer()?我将包括我的Sign()方法来显示它是如何实现的。哈哈,非常感谢,问题是我在代码中初始化了两次googleClassroomService,所以授权人被重置了,谢谢!但是我的代码正在运行“错误:响应不是文件列表”你知道为什么会这样吗?你得到的是一个GTLR教室列表CourseSResponse,而不是GTLRClassroomQuery课程列表。我已经实现了谷歌登录,我可以使用这个谷歌驱动器选择器访问谷歌驱动器[当进入我的应用程序时,我会浏览登录屏幕。您是否也设置了googleClassroomService.authorizer=user.authentication.fetcherAuthorizer()?我将包括我的sign()方法来显示它是如何实现的。哈哈,非常感谢,问题是我在代码中初始化了两次googleClassroomService,所以授权人被重置了,谢谢!但是我的代码正在运行“错误:响应不是文件列表”你知道为什么会出现这种情况吗?你得到的是一个GTLR教室列表课程响应,而不是GTLR教室查询课程列表。