为什么我不能使用Google Classroom API?

时间:2015-07-02 12:07:18

标签: java google-classroom

我在使用Google Developer Console时遇到问题,我无法使用Google Classroom的新API。我不明白这一点,因为谷歌已经让我早期访问这个API。 当我尝试执行文档中出现的Java快速入门指南时,项目执行失败。在命令行中出现:

ABCCCCCCC

异常的堆栈跟踪:

/home/usuario/eclipseWorkspace/pruebasDeClassroom/src/main/java/ClassroomQuickstart.java:41: error: cannot find symbol
    Arrays.asList(ClassroomScopes.CLASSROOM_COURSES_READONLY);
                  ^
symbol:   variable ClassroomScopes
location: class ClassroomQuickstart

1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

我认为这是因为Google开发者控制台中尚未提供Classroom API,但我不确定。实际上,如果您转到Google Developers Console> API,您搜索API教室,您将找不到任何启用。我也尝试了Gmail的Java快速入门指南,它运行正常(Gmail API可用,我启用了测试)。

我需要知道是否有针对此问题的解决方案。谢谢你的时间。

2 个答案:

答案 0 :(得分:3)

此问题是由于示例代码中缺少import语句:

import com.google.api.services.classroom.ClassroomScopes;

现在样本已修复。感谢您引起我们的注意。

答案 1 :(得分:1)

各种API方法的范围在各种REST API的文档中定义。从该文档中,可以轻松构建文件的替换:

public final class ClassroomScopes {
   // Read only access to the courses, for use in the "courses.list"
   // and "courses.get" API methods. See the documentation here:
   // https://developers.google.com/classroom/reference/rest/v1/courses/list
   // https://developers.google.com/classroom/reference/rest/v1/courses/get
   public static final String CLASSROOM_COURSES_READONLY = 
       "https://www.googleapis.com/auth/classroom.courses.readonly";

   // Prevent instantiation
   private ClassroomScopes() {}
}

...虽然我鼓励您使用QuickStart Java页面上的“发送反馈”链接来指示这不是开箱即用(文件不存在或文件存在,但它不在同一个包中,并且缺少导入)这样就可以解决这个问题。