我和我的同事有一个 C# WPF 项目,它管理 Google Classroom 中的课程。
我们在 Google API 平台中创建项目。我们是该项目的所有者。
两者都有 OAuth 2.0 客户端 ID。 (但这并不重要)
我允许 Classroom API 的所有范围。
我是 Gsuite for Education 的域管理员。域中允许使用 Google Classroom API。
他可以登录并使用该程序,没有任何错误,各项功能都正常。
我不能,因为我收到错误 400,invalid_request 帐户受限。
我尝试使用 API Explorer,只有当我想获取谷歌课堂课程的主题列表时才会出现此错误。
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";
}