How to get absolute path of a document and file from Google Drive Using Java Drive Rest V2 API?

前端 未结 2 1339
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 00:23

I\'m working on Google Drive Integration using Java Drive Rest V2 API, I\'m able to get most of the document/file metadata properties excep

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 00:40

    Try using the Parents.get. A successful request returns a link to both parent and the file itself. Here's a sample response:

    {
     "kind": "drive#parentReference",
     "id": "0Bw-w9jw2bwglbzlvMVh2cll2dmM",
     "selfLink": "https://www.googleapis.com/drive/v2/files/1-ABCDEzyvp9NFmWz7h6ssgkTKHytO1Nq4SNIboDW8A/parents/0Bw-w9jw2bwglbzlvMVh2cll2dmM",
     "parentLink": "https://www.googleapis.com/drive/v2/files/ABCDEjw2bwglbzlvMVh2cll2dmM",
     "isRoot": false
    }
    

    Here's the JAVA implementation from the docs:

     private static boolean isFileInFolder(Drive service, String folderId,
          String fileId) throws IOException {
        try {
          service.parents().get(fileId, folderId).execute();
        } catch (HttpResponseException e) {
          if (e.getStatusCode() == 404) {
            return false;
          } else {
            System.out.println("An error occured: " + e);
            throw e;
          }
        } catch (IOException e) {
          System.out.println("An error occured: " + e);
          throw e;
        }
        return true;
      }
    

提交回复
热议问题