0

Google 엔드 포인트 및 Google 앱 엔진을 사용하여 Android 애플리케이션을 개발 중입니다. 내 백엔드는 실제로 아무 것도하지 않는 것 같습니다. 아무 것도 데이터 저장소에 저장되지 않아서 아무것도 검색 할 수없는 것처럼 보입니다.Google 애플리케이션 엔진 엔티티가 생성되지 않습니다.

private static String getUserId(User user) { 
     String userId = user.getUserId(); 
     if (userId == null) { 
      AppEngineUser appEngineUser = new AppEngineUser(user); 
      ofy().save().entity(appEngineUser).now(); 
      // Begin new session for not using session cache. 
      Objectify objectify = ofy().factory().begin(); 
      AppEngineUser savedUser = objectify.load().key(appEngineUser.getKey()).now(); 
      userId = savedUser.getUser().getUserId(); 
     } 
     return userId; 
    } 

    @ApiMethod(name = "saveProfile", path = "profile", httpMethod = ApiMethod.HttpMethod.POST) 
    public Profile saveProfile(final User user, final ProfileForm profileForm) throws UnauthorizedException { 
     if(user == null) { 
      throw new UnauthorizedException("Authorization required."); 
     } 

     String firstName = profileForm.getFirstName(); 
     String surname = profileForm.getLastName(); 
     String userEmail = user.getEmail(); 
     int year = profileForm.getYear(); 
     int month = profileForm.getMonth(); 
     int day = profileForm.getDay(); 

     Profile profile = ofy().load().key(Key.create(Profile.class, getUserId(user))).now(); 

     if (profile == null) { 
      // the user does not have a profile and is creating one for the first time 
      profile = new Profile(getUserId(user), firstName, surname, userEmail, year, month, day); 
     } else { 
      profile.update(firstName, surname, userEmail, year, month, day); 
     } 
     ofy().save().entity(profile).now(); 
     return profile; 
    } 

    @ApiMethod(name = "getProfile", path = "profile", httpMethod = ApiMethod.HttpMethod.GET) 
    public Profile getProfile(User user) throws UnauthorizedException { 
     if (user == null) { 
      throw new UnauthorizedException("Authentication required."); 
     } 
     return ofy().load().key(Key.create(Profile.class, getUserId(user))).now(); 
    } 
} 

프로파일 클래스 @Entity 주석을 가지며과 같이 정적 블록 객관화 등록된다 : 작동하지 않는 것은 여기

는 I 엔드 포인트에 기입 한 API 메소드 중 일부

static { 
     factory().register(AppEngineUser.class); 
     factory().register(Profile.class); 
} 

사용자 ID는

com.google.appengine.api.users.User 
통해 GAE 의해 생성

userId 속성은 @Index 주석이있는 문자열입니다.

나는 API 탐색기와이 방법에 어떻게 반응하는지 혼동합니다. saveProfile API 메서드를 호출 할 때마다 userId0이고 이메일이 "[email protected]" 인 경우 프로필 개체가 반환됩니다. 로컬 호스트에서 실행될 때 기본 전자 메일이라고 생각합니다.

HTTP를 통해 api explorer도 실행 중이므로 Google에서이 문제가 발생할 수 있다고 말합니다. 이것이 아무 것도 작동하지 않는 이유입니다. 내 API를 사용하기 위해 안전하지 않은 스크립트를로드해야했지만, HTTPS 대신 HTTP를 통해 호스팅되기 때문에 작동하지 않을 수도 있습니다.

GAE를 이해하는 데있어 근본적인 결함이 있거나 로컬 호스트에서 실행되고 있기 때문에 완전히 내 방법을 테스트 할 수없는 문제입니다. 아마 후자의 경우 Appspot에 배포해야하며 상황이 더 원활하게 수행 될 수 있습니다.

도움이 필요한 추가 사항이있는 경우 그냥 물어보십시오.

감사합니다.

답변

1

개발자 콘솔에서 로그를 확인하십시오. 실행중인 모든 API 메소드를 기록하고 오류가있는 경우 표시합니다.

사용자의 전자 메일로 [email protected]을 받고 있으므로 사용자가 GAE에 의해 주입되지 않았다고 생각됩니다. 이는 잘못된 클라이언트 측 (예 : Android)을 수행하고 있기 때문일 수 있습니다. Android 앱이 Google에 사용자를 기록하고 Android의 빌더 객체에 해당 자격 증명을 전달하도록 올바르게 요청해야합니다.

api 탐색기를 통해 API 메소드를 실행하는 경우 해당 사용자 객체가 메소드에 채워지는 경우 먼저 Google 사용자로 로그인해야합니다 (이미 알고있는 것으로 생각됩니다).

요약하면 로그와 클라이언트 코드를 확인하십시오.

관련 문제