Search code examples
google-apigoogle-drive-apidrive

Find file's parent id : Google Drive API V3


enter image description here

Today after I updated my Drive API to V3, I dint find any method to find the parent of the selected file . Is the rest endpoint to fetch json related to parent's info changed?


Solution

  • If you have the file id of the file in question then Files: get you need to add fields ie parents along with the file id.

    Request

    GET https://www.googleapis.com/drive/v3/files/0B5pJkOVaKccENWNNcFFaU2lSM0E?fields=parents&key={YOUR_API_KEY}

    Returns

    { "parents": [ "0B5pJkOVaKccEYW5lVHBKd1Zwc28" ] }

    The result is actually a file id. Remember files and directories are the same in Drive.

    Do files.get again

    GET https://www.googleapis.com/drive/v3/files/0B5pJkOVaKccEYW5lVHBKd1Zwc28?key={YOUR_API_KEY}

    Results

    { "kind": "drive#file", "id": "0B5pJkOVaKccEYW5lVHBKd1Zwc28", "name": "SiteBackups", "mimeType": "application/vnd.google-apps.folder" }