Parents: list

Stay organized with collections Save and categorize content based on your preferences.

Lists a file's parents. Try it now or see an example.


HTTP request



Parameter name Value Description
Path parameters
fileId string The ID of the file.


This request requires authorization with at least one of the following scopes:


Some scopes are restricted and require a security assessment for your app to use them. For more information, see the authentication and authorization page.

Request body

Do not supply a request body with this method.


If successful, this method returns a response body with the following structure:

  "kind": "drive#parentList",
  "etag": etag,
  "selfLink": string,
  "items": [
    parents Resource
Property name Value Description Notes
kind string This is always drive#parentList.
etag etag The ETag of the list.
items[] list The list of parents.


Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).


Uses the Java client library.



// ...

public class MyClass {

  // ...

   * Print a file's parents.
   * @param service Drive API service instance.
   * @param fileId ID of the file to print parents for.
  private static void printParents(Drive service, String fileId) {
    try {
      ParentList parents = service.parents().list(fileId).execute();

      for (ParentReference parent : parents.getItems()) {
        System.out.println("File Id: " + parent.getId());
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);

  // ...



Uses the .NET client library.

using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

// ...

public class MyClass {

  // ...

  /// <summary>
  /// Print a file's parents.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to print parents for</param>
  public static void PrintParents(DriveService service, String fileId) {
    ParentsResource.ListRequest request = service.Parents.List(fileId);

    try {
      ParentList parents = request.Execute();

      foreach (ParentReference parent in parents.Items) {
        Console.WriteLine("File Id: " + parent.Id);
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);

  // ...



Uses the PHP client library.

 * Print a file's parents.
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to print parents for.
function printParents($service, $fileId) {
  try {
    $parents = $service->parents->listParents($fileId);

    foreach ($parents->getItems() as $parent) {
      print 'File Id: ' . $parent->getId();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();


Uses the Python client library.

from apiclient import errors
# ...

def print_parents(service, file_id):
  """Print a file's parents.

    service: Drive API service instance.
    file_id: ID of the file to print parents for.
    parents = service.parents().list(fileId=file_id).execute()
    for parent in parents['items']:
      print 'File Id: %s' % parent['id']
  except errors.HttpError, error:
    print 'An error occurred: %s' % error


Uses the JavaScript client library.

 * Print a file's parents.
 * @param {String} fileId ID of the file to insert.
function printParents(fileId) {
  var request ={
    'fileId': fileId
  request.execute(function(resp) {
    for (parent in resp.items) {
      console.log('File Id: ' + resp.items[parent].id);


Uses the Go client library.

import (

// PrintParents displays the parents of a given file
func PrintParents(d *drive.Service, fileId string) error {
  r, err := d.Parents.List(fileId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  for _, p := range r.Items {
    fmt.Printf("Folder with ID: %v", p.Id)
  return nil


Uses the Objective-C client library.

#import "GTLDrive.h"
// ...

+ (void)printFilesInFolderWithService:(GTLServiceDrive *)service
                               fileId:(NSString *)fileId {
  GTLQueryDrive *query = [GTLQueryDrive queryForParentsListWithFileId:fileId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveParentList *parents, NSError *error) {
          if (error == nil) {
            for (GTLDriveParentReference *parent in parents) {
              NSLog(@"File Id: %@", parent.identifier);
          } else {
            NSLog(@"An error occurred: %@", error);

// ...

Try it!

Use the APIs Explorer below to call this method on live data and see the response.