我如何获得当前的Gmail登录信息

时间:2016-05-04 08:00:58

标签: java spring-mvc gmail

我有一个web-appl:Spring MVC 4,Spring Data,Spring Security。如何登录(电子邮件)当前用户登录gmail帐户。我尝试从HttpServletRequest获取cookie,但它不存储此数据。 我试着像这样得到cookie:

CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);
    //creates url for the given string
    URL url = null;
    try {
        url = new URL("https://www.google.co.in/");
        //open's a connection with the url specified and returns URLConnection object
        URLConnection  urlConnection = url.openConnection();
        // get's the contents from this url specifies
        urlConnection.getContent();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //returns the cookie store(bunch of cookies)
    CookieStore cookieStore = cookieManager.getCookieStore();
    //getting cookies which returns in the form of List of type HttpCookie
    List<HttpCookie> listOfcookies = cookieStore.getCookies();
    for(HttpCookie httpCookie: listOfcookies){
        System.out.println("Cookie Name : "+httpCookie.getName()+" Cookie Value : "+httpCookie.getValue());
    }

0 个答案:

没有答案