当前位置: 首页 > 知识库问答 >
问题:

使用GoogleAPI时出现Tomcat启动错误

阎星河
2023-03-14

我对GoogleAPI有些问题。

HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collections;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonParser;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;

import airbnb.dao.CustomerDAO;
import airbnb.vo.CustomerVO;


public class CustomerController extends HttpServlet{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private static final String CLIENT_ID = "Client_id";

    @Override
    public void init() throws ServletException {




    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String mode = req.getParameter("mode");
        //String customerCheck = req.getParameter("customerName");
        System.out.println("customerCheck");





        String id_token = req.getParameter("id_token");
        System.out.println("id_token"+id_token);

        HttpTransport transport = new NetHttpTransport();//*
        JsonFactory jsonFactory = new JacksonFactory();//*


        GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
                .setAudience(Collections.singletonList(CLIENT_ID))
                // Or, if multiple clients access the backend:
                //.setAudience(Arrays.asList(CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3))
                .build();


            GoogleIdToken idToken = null;
            try {
                idToken = verifier.verify(id_token);
            } catch (GeneralSecurityException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
                if (idToken != null) {
                    Payload payload = idToken.getPayload();

                    // Print user identifier
                    String userId = payload.getSubject();
                    System.out.println("User ID: " + userId);

                    // Get profile information from payload
                    String email = payload.getEmail();
                    boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
                    String name = (String) payload.get("name");
                    String pictureUrl = (String) payload.get("picture");
                    String locale = (String) payload.get("locale");
                    String familyName = (String) payload.get("family_name");
                    String givenName = (String) payload.get("given_name");

                    // Use or store profile information
                    // ...
                     System.out.println("User ID: " + userId);
                      System.out.println("email: " + email);
                      System.out.println("emailVerified: " + emailVerified);
                      System.out.println("name: " + name);
                      System.out.println("pictureUrl: " + pictureUrl);
                      System.out.println("locale: " + locale);
                      System.out.println("familyName: " + familyName);
                      System.out.println("givenName: " + givenName);

                } else {
                    System.out.println("Invalid ID token.");
                }   
    }
}

这是错误。

条件:jdk 1.8,Tomcat 8.5

请帮我解决这个错误。

共有1个答案

公良俊楚
2023-03-14

检查此行:

java.lang.NoClassDefFoundError: com/google/api/client/http/HttpTransport

您需要从这里在Tomcat类路径中添加google-api-clientjar文件

 类似资料:
  • 我试图在xampp控制面板v3.2.1上用xampp 1.8.3启动tomcat,但出现了以下错误: Tomcat启动/停止错误,返回代码:1确保您安装了JavaJDK或JRE,并且所需的端口是免费的查看“/xampp/tomcat/logs”文件夹了解更多信息 谁能帮帮我?我正在用windows 7 如果我的英语不完美,我很抱歉

  • 我已经在我的Win 10上安装了XAMPP 7.2.10,Apache和MySQL等其他服务运行良好。但是Tomcat服务没有启动,并且会抛出一个错误:“Tomcat Started/Stopded with error,返回代码:1,确保您安装了JavaJDK或JRE,并且所需的端口是免费的,检查“/xampp/tomcat/logs”文件夹以获取更多信息”XAMPP Tomcat错误图像 我在

  • 我正在intellij上启动一个tomcat服务器(没有部署任何东西),但我得到以下错误。我一直在找它,但没有运气。你能帮帮我吗? 编辑: 应用程序.属性:

  • 当我试图从web.xml映射ApplicationContext.xml文件以使用spring ioc时,我的应用程序没有开始在catalina.out中显示以下错误

  • 在尝试启动节点后,出现以下错误。js。有人知道下面错误的可能解决方案吗。我没用过node。根本没有。请帮忙! http://i.stack.imgur.com/eri49.png

  • 我使用的是STS 3.6.0,在STS启动期间,我发现错误: 我不能为这个项目运行Gradle任务。有什么建议吗?