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";
}
Any idea?