Google Classroom,Ruby,Rails:带有测试帐户的@NotGoogleAppsUser

时间:2016-07-18 17:21:56

标签: ruby-on-rails ruby google-api google-apps google-classroom

我已经从Google获得了Classroom的测试帐户(也就是说,除了课堂之外的所有服务都已禁用)。按照https://developers.google.com/classroom/quickstart/ruby中的示例(略有修改),我可以登录并获取详细信息,例如关于学生的课程。

但是,我想要做的是在Rails应用程序中使用它。我正在使用omniauth-google-oauth2google-api-ruby-client(新的0.9.x分支)。从Google获取该测试帐户的令牌后(我已经检查过它是此帐户而不是我使用的任何其他配置文件)我试图从{访问数据{1}},但它一直告诉我:

Sending HTTP get https://classroom.googleapis.com/v1/courses?pageSize=10
403
#<Hurley::Response GET https://classroom.googleapis.com/v1/courses?pageSize=10 == 403 (319 bytes) 748ms>
Caught error forbidden: @NotGoogleAppsUser The user is not a Google Apps user.
Error - #<Google::Apis::ClientError: forbidden: @NotGoogleAppsUser The user is not a Google Apps user.>

Google::Apis::ClientError: forbidden: @NotGoogleAppsUser The user is not a Google Apps user.

我使用的代码是:

require 'google/apis/classroom_v1'

module GoogleIntegration::Client
  Classroom = Google::Apis::ClassroomV1

  def self.create(token)
    service = Classroom::ClassroomService.new
    scopes = ['https://www.googleapis.com/auth/classroom.courses.readonly', 'profile', 'email']
    service.authorization = Google::Auth.get_application_default(scopes)
    service.authorization.access_token = token
    service.client_options.application_name = 'Membean Classroom Sample'
    service
  end

并在控制器中:

service = GoogleIntegration::Client.create(request.env['omniauth.auth'].credentials.token)
response = service.list_courses(page_size: 10)

1 个答案:

答案 0 :(得分:0)

根据课堂API Access Errors

  

NotGoogleAppsUser 表示请求的用户不属于   到Google Apps域。

     

可能的操作:提示用户使用“Google”重新进行身份验证   “教育应用”帐户。提供使用multiple accounts的链接   用户可以选择正确的帐户。