I've got a test account for Classroom from Google (that is, all services apart from Classroom are disabled for it). Following the example as in https://developers.google.com/classroom/quickstart/ruby (with slight modifications), I'm able to log in and fetch details e.g. about the student's courses.
However what I want to do is utilize it in a Rails app. I'm using omniauth-google-oauth2 and google-api-ruby-client (the new 0.9.x branch). After having fetched the token for that test account from Google (I've triple checked that it is this account and not any other profile I use) I'm trying to access data from Google::Apis::ClassroomV1::ClassroomService, but it keeps telling me:
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.
The code I use is:
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
and in the controller:
service = GoogleIntegration::Client.create(request.env['omniauth.auth'].credentials.token) response = service.list_courses(page_size: 10)