2015-07-02 58 views
0

我有一個Google Developer Console的問題,是我無法使用Google Classroom的新API。我不明白這一點,因爲谷歌給了我早期訪問這個API。 當我嘗試執行文檔中出現的Java快速入門指南時,項目執行失敗。在命令行中出現這樣的:爲什麼我無法使用Google Classroom API?

/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. 

和異常的堆棧跟蹤:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileJava'. 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) 
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) 
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) 
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) 
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) 
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:306) 
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) 
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63) 
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51) 
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23) 
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88) 
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) 
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62) 
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23) 
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68) 
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62) 
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55) 
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149) 
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106) 
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86) 
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80) 
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) 
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) 
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36) 
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) 
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51) 
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169) 
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237) 
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210) 
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35) 
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24) 
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206) 
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169) 
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) 
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) 
at org.gradle.launcher.Main.doAction(Main.java:33) 
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) 
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54) 
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35) 
at org.gradle.launcher.GradleMain.main(GradleMain.java:23) 
Caused by: 
org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. 
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:44) 
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:35) 
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:97) 
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:50) 
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:36) 
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:34) 
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25) 
at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:156) 
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:136) 
at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:90) 
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63) 
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:235) 
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211) 
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:222) 
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) 
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) 
... 44 more 

我認爲,這是因爲課堂API還沒有提供在谷歌開發者控制檯,但我不確定。實際上,如果您轉到Google Developers Console> API,並且在API教室中搜索,則無法啓用任何功能。我也嘗試使用Gmail的Java快速入門指南,它可以正常工作(Gmail API可用,並且我已啓用測試)。

我需要知道是否有針對此問題的解決方案。感謝您的時間。

回答

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頁面上的「發送反饋」鏈接,以表明這不是開箱即用(文件不存在或文件存在,但不在同一個包中,並且缺少一個導入文件),這樣就可以解決問題。

3

此問題是由於在示例代碼缺少import語句:現在

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

樣品是固定的。謝謝讓我們注意到這個。

相關問題