为Google App Engine API后端添加OAuth失败

时间:2013-11-24 20:36:24

标签: java google-app-engine maven oauth

我正在学习如何为Google App引擎创建API后端。 作为我学习的一部分,我已成功实施以下教程

https://developers.google.com/appengine/docs/java/endpoints/getstarted/backend/write_api https://developers.google.com/appengine/docs/java/endpoints/getstarted/backend/write_api_post

但是当我尝试按照本教程中的描述添加oAuth时, https://developers.google.com/appengine/docs/java/endpoints/getstarted/backend/auth

我收到以下错误(在 mvn应用引擎:更新期间)

  

[ERROR] /Users/raj/Documents/workspace/rajmaven/helloendpoints/src/main/java/com/google/devrel/samples/helloendpoints/Greetings.java:[18,14]错误:找不到符号   [错误]符号:变量常量

我无法找到错误背后的确切原因。有人可以帮我解决这个问题。

  1 package com.google.devrel.samples.helloendpoints;
  2 
  3 import com.google.api.server.spi.config.Api;
  4 import javax.inject.Named;
  5 import java.util.ArrayList;
  6 import com.google.api.server.spi.config.ApiMethod;
  7 import com.google.appengine.api.users.User;
  8 
  9 /**
 10  * Defines v1 of a helloworld API, which provides simple "greeting" methods.
 11  */
 12 /*@Api(name = "helloworld", version = "v1") */
 13 
 14 
 15 @Api(
 16     name = "helloworld",
 17     version = "v1",
 18     scopes = {Constants.EMAIL_SCOPE},
 19     clientIds = {com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID}
 20 )
 21 public class Greetings {
 22   public static ArrayList<HelloGreeting> greetings = new ArrayList<HelloGreeting>();
 23 
 24   static {
 25     greetings.add(new HelloGreeting("hello world!"));
 26     greetings.add(new HelloGreeting("goodbye world!"));
 27   }
 28 
 29   public HelloGreeting getGreeting(@Named("id") Integer id) {
 30     return greetings.get(id);
 31   }
 32 
 33 @ApiMethod(name = "greetings.authed", path = "greeting/authed")
 34 public HelloGreeting authedGreeting(User user) {
 35   HelloGreeting response = new HelloGreeting("hello " + user.getEmail());
 36   return response;
 37 }
 38 
 39 
 40 @ApiMethod(name = "greetings.multiply", httpMethod = "post")
 41 public HelloGreeting insertGreeting(@Named("times") Integer times, HelloGreeting greeting) {
 42   HelloGreeting response = new HelloGreeting();
 43   StringBuilder responseBuilder = new StringBuilder();
 44   for (int i = 0; i < times; i++) {
 45     responseBuilder.append(greeting.getMessage());
 46   }
 47   response.setMessage(responseBuilder.toString());
 48   return response;
 49 }
 50 
 51 
 52 }

1 个答案:

答案 0 :(得分:2)

我已经确定了这个问题;我必须提供常数。看起来教程错过了提及。我从API后端应用程序https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-java-maven

的代码存储库中找到了它