AEM中的Google驱动集成

AEM中的Google驱动集成,aem,Aem,我想在aem中集成google drive,并想在aem中获取google drive中存在的文件夹的所有照片。 我使用了云服务,并且能够使用auth2获取pageToken。 现在我想使用RESTAPI以json的形式获取该文件夹中所有文件的列表。有人能给我一些建议,我怎样才能做到 public JSONObject ImagesJson(String accessToken) throws IOException,JSONException { String url = "h

我想在aem中集成google drive,并想在aem中获取google drive中存在的文件夹的所有照片。 我使用了云服务,并且能够使用auth2获取pageToken。 现在我想使用RESTAPI以json的形式获取该文件夹中所有文件的列表。有人能给我一些建议,我怎样才能做到

  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) {
                    is = httpConn.getErrorStream();
                }
            }
            return e.getMessage();
        }
    }
    return null;
}

我正在接受此代码的帮助,但响应为400。请帮助。

您确定使用正确的参数点击了正确的url吗?尝试通过从web浏览器或curl点击url来获得所需的结果,然后用java实现。是的,我确信我已经完成了任务。我将很快在这里与您分享完整的ans。