wpfgoogle-apis-explorergoogle-classroomgoogle-workspace

Account restricted to google Classroom API


My collague and I have a C# WPF project, which manage courses in Google Classroom. We create the project in Google API platform. We are the owner of the project. Both have OAuth 2.0 Client IDs. (but it doesn't matter) I allow all of Classroom API's scope.

I am the domain admin of our Gsuite for Education. Google Classroom API is allowed in the domain.

He can login and use the program, there is not any error, every function is ok. I can't, because i got an error 400, invalid_request Account restricted.

I try with API Explorer, and this error occurs only when I would like to get the list of topics of a google classroom course.

Scope: https://www.googleapis.com/auth/classroom.topics https://www.googleapis.com/auth/classroom.topics.readonly openid

        txtLog.Text += "Try login to Google...\n"; 
        UserCredential credential;

        using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
        {
            
            // The file token.json stores the user's access and refresh tokens, and is created
            // automatically when the authorization flow completes for the first time.
            string credPath = "token.json";
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new string[] 
                { 
                    ClassroomService.Scope.ClassroomCourses, 
                    ClassroomService.Scope.ClassroomRosters, 
                    ClassroomService.Scope.ClassroomProfileEmails, 
                    ClassroomService.Scope.ClassroomProfilePhotos,
                    ClassroomService.Scope.ClassroomTopics
                },
                "admin",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
            txtLog.Text += $"Credential file saved to: {credPath}\n";
        }

        // Create Classroom API service.
        service = new ClassroomService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Jedlik Classroom Manager",
        });

        // Define request parameters.
        CoursesResource.ListRequest request = service.Courses.List();
        request.PageSize = 100;

        // List courses.
        ListCoursesResponse response = request.Execute();
        if (response.Courses != null && response.Courses.Count > 0)
        {
            txtLog.Text +=$"Number of coureses: {response.Courses.Count}\n";
            lstCourses.ItemsSource = response.Courses.ToList();
            lstCourses.DisplayMemberPath = "Name";
            lstCourses.SelectedValuePath = "Id";
            lstCourses.SelectedIndex = 0;
        }
        else
        { 
            txtLog.Text += $"No courses found\n";
        }

Solution

  • Answer:

    This sounds like a problem with your account. To get a resolution you should contact G Suite support.

    More Information:

    If there is an account restriction on the account trying to authenticate then this isn't something that the Stack Overflow community can help with - especially if the same code works for another teacher on your domain and that you are receiving the same response in the Try this API function on the courses.topics reference page.

    You can contact G Suite Support using the links on this page

    Update 2020.06.01:

    This actually appears to be a bug!

    There is a report on Google's Issue Tracker which detail the same kind of behaviour:

    Google does seem to know about this issue given the reponses but I figured it would be good to give this an update.

    For future readers: if this hasn't yet been fixed you can also hit the ☆ next to the issue number in the top left on the aforementioned issue page which lets Google know more people are encountering this and so it is more likely to be seen to faster.

    References: