Google app engine Google Plus应用程序登录凭据

Google app engine Google Plus应用程序登录凭据,google-app-engine,google-plus,Google App Engine,Google Plus,我正在创建一个应用程序,我想确认用户在Java环境中使用Google凭据。可以使用GoogleAPI完成,但我不确定如何将其编码为servlet 我找到一个代码段来授权凭据,但AuthorizationCodeInstalledApp()引发了一个错误,我不确定要使用哪个api private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets cl

我正在创建一个应用程序,我想确认用户在Java环境中使用Google凭据。可以使用GoogleAPI完成,但我不确定如何将其编码为servlet

我找到一个代码段来授权凭据,但AuthorizationCodeInstalledApp()引发了一个错误,我不确定要使用哪个api

private static Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
        new InputStreamReader(Test.class.getResourceAsStream("/client_secrets.json")));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
        || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
      System.out.println(
          "Enter Client ID and Secret from https://code.google.com/apis/console/?api=plus "
          + "into plus-cmdline-sample/src/main/resources/client_secrets.json");
      System.exit(1);
    }
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        httpTransport, JSON_FACTORY, clientSecrets,
        Collections.singleton(PlusScopes.PLUS_ME)).setDataStoreFactory(
        dataStoreFactory).build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
  }

希望有人能在这方面帮助我,并让我知道这个过程,这将是伟大的…

如果你真的要编写一个servlet在谷歌AppEngine下运行,这比这要容易得多。


这是否允许我对用户进行身份验证?应如何对用户进行身份验证?如何登录系统
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

...

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
  UserService userService = UserServiceFactory.getUserService();
  User currentUser = userService.getCurrentUser();
  if (currentUser == null) {
    resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
  }
  else {
    // show the view
  }
}