Google API : Getting a Contacts Photo

后端 未结 4 2050
闹比i
闹比i 2021-02-14 09:02

I\'ve been able to retrieve everything but the contacts photo by following the API.

I can get the img url as well as the gd:etag from the xml returned. Below is the Goog

4条回答
  •  萌比男神i
    2021-02-14 09:32

    Use the same authorized request code used for retrieving contacts and just replace the url with the link rel url of the contact image. Response will be the bytes of the image. Use the following code to return image as response.

            //'in' is the inputStream returning from the call, response is the HttpServletResponse
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            int read;
            while (true) {
                 if ((read = in.read(buffer)) != -1) {
                    out.write(buffer, 0, read);
                } else {
                    break;
                }
            }
            response.setContentType("image/jpeg");
            response.setContentLength(buffer.length);
            request.getSession().setAttribute("image", new String(out.toByteArray()));
            response.getOutputStream().write(buffer); 
    

提交回复
热议问题