Google Drive API JAVA用户类

时间:2020-11-25 15:27:27

I am trying to get the name of the authorized user of google drive using this code :

我想使用此代码获取google驱动器的授权用户的名称:

public class list extends HttpServlet{

    private DbxClient client;
    String token;

    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{

        try{
            DbxRequestConfig requestConfig = new 
            DbxRequestConfig("JavaDropBoxTutorial/1.0",Locale.getDefault().toString() );

            HttpSession session = req.getSession();
            token = session.getAttribute("access_token").toString();

            client = new DbxClient(requestConfig, token);

                    session.setAttribute("dropuser",client.getAccountInfo().displayName);

            User u = new User();
            System.out.print(u.getDisplayName());

            res.sendRedirect("listdetails.jsp");
        }
        catch(Exception e){
        }
    }
}

But I get this Error : -

但我得到这个错误: -

HTTP Status 500 - Servlet execution threw an exception

HTTP状态500 - Servlet执行引发异常

With the exception

有这个特例

javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

javax.servlet.ServletException:Servlet执行引发异常org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.NoClassDefFoundError: com/google/common/base/Preconditions

1 个解决方案

#1


Your code and Error not clearing question but you may be looking for below(as per comment) :

您的代码和错误没有清除问题,但您可能正在寻找以下(根据评论):

Use below code to get user name of authorized user of google drive :

使用以下代码获取google驱动器的授权用户的用户名:

  try {
      About about = service.about().get().execute();
      System.out.println("Current user name: " + about.getName());

    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }

You can get more details Here

你可以在这里获得更多细节

#1


Your code and Error not clearing question but you may be looking for below(as per comment) :

您的代码和错误没有清除问题,但您可能正在寻找以下(根据评论):

Use below code to get user name of authorized user of google drive :

使用以下代码获取google驱动器的授权用户的用户名:

  try {
      About about = service.about().get().execute();
      System.out.println("Current user name: " + about.getName());

    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }

You can get more details Here

你可以在这里获得更多细节