Raj
Raj

Reputation: 2398

Adding OAuth fails for Google App Engine API Backend

I am learning how to create API Backend for Google App engine. As part of my learning, I have successfully implemented the following tutorials

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

But when I tried to add oAuth as described in this tutorial, https://developers.google.com/appengine/docs/java/endpoints/getstarted/backend/auth

I am getting the following error(during mvn app engine:update)

[ERROR] /Users/raj/Documents/workspace/rajmaven/helloendpoints/src/main/java/com/google/devrel/samples/helloendpoints/Greetings.java:[18,14] error: cannot find symbol [ERROR] symbol: variable Constant

I am not able to locate the exact reason behind the error. Can some help me on this.

  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 }

Upvotes: 2

Views: 328

Answers (1)

Raj
Raj

Reputation: 2398

I have identified the issue ; I have to supply the Constants. Looks like the tutorial missed to mention about that. I found it from the Code repository of the API back-end application https://github.com/GoogleCloudPlatform/appengine-endpoints-helloendpoints-java-maven

Upvotes: 2

Related Questions