Google Drive Integration in AEM -
i want integrate google drive in aem , want fetch photos of folder exist in google drive in aem. used cloud services , able fetch pagetoken using auth 2. want fetch list of files in folder in form of json using rest api. can advice me,how can achieve ?
public jsonobject imagesjson(string accesstoken) throws ioexception,jsonexception { string url = "https://content.googleapis.com/drive/v2/files/{folder-id}/children?key={server-key}"; string str = gethttpresponse(url, accesstoken); jsonobject jsonobject = new jsonobject(str); return jsonobject; } public static string gethttpresponse(string url, string accesstoken) throws ioexception { httpsurlconnection urlconnection = null; inputstream is=null; if (url != null && url.trim().length() > 0) { try { url _url = new url(url); urlconnection = (httpsurlconnection) _url.openconnection(); urlconnection.setrequestmethod("get"); urlconnection.setrequestproperty("authorization", "bearer " + accesstoken); int responsecode = urlconnection.getresponsecode(); system.out.println("response code -- -- -- -- -- -- " + responsecode); inputstream inputstream = urlconnection.getinputstream(); bufferedreader in = new bufferedreader(new inputstreamreader(inputstream)); string inputline; stringbuffer response = new stringbuffer(); while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); return response.tostring(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { if (urlconnection instanceof httpurlconnection) { httpurlconnection httpconn = urlconnection; int statuscode = httpconn.getresponsecode(); if (statuscode != 200) { = httpconn.geterrorstream(); } } return e.getmessage(); } } return null; }
i taking of code response coming 400.please help.
Comments
Post a Comment