Comments: list

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

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

Request

HTTP request

GET https://www.googleapis.com/drive/v2/files/fileId/comments

Parameters

Parameter name Value Description
Path parameters
fileId string The ID of the file.
Optional query parameters
includeDeleted boolean If set, all comments and replies, including deleted comments and replies (with content stripped) will be returned. (Default: false)
maxResults integer The maximum number of discussions to include in the response, used for paging. Acceptable values are 0 to 100, inclusive. (Default: 20)
pageToken string The continuation token, used to page through large result sets. To get the next page of results, set this parameter to the value of "nextPageToken" from the previous response.
updatedMin string Only discussions that were updated after this timestamp will be returned. Formatted as an RFC 3339 timestamp.

Authorization

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

Scope
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.file

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.

Response

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

{
  "kind": "drive#commentList",
  "selfLink": string,
  "nextPageToken": string,
  "nextLink": string,
  "items": [
    comments Resource
  ]
}
Property name Value Description Notes
kind string This is always drive#commentList.
nextPageToken string The page token for the next page of comments. This will be absent if the end of the comments list has been reached. If the token is rejected for any reason, it should be discarded, and pagination should be restarted from the first page of results.
items[] list The list of comments. If nextPageToken is populated, then this list may be incomplete and an additional page of results should be fetched.

Examples

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).

Java

Uses the Java client library.

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Comment;
import com.google.api.services.drive.model.CommentList;

import java.io.IOException;
import java.util.List;

// ...

public class MyClass {

  // ...

  /**
   * Retrieve a list of comments.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to retrieve comments for.
   * @return List of comments.
   */
  private static List<Comment><comment> retrieveComments(Drive service,
      String fileId) {
    try {
      CommentList comments = service.comments().list(fileId).execute();
      return comments.getItems();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }
    return null;
  }

  // ...

}</comment>

.NET

Uses the .NET client library.

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

using System.Collections.Generic;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Retrieve a list of comments.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to retrieve comments for.</param>
  /// <returns>List of comments.</returns>
  public static IList<Comment><Comment> RetrieveComments(DriveService service, String fileId) {
    try {
      CommentList comments = service.Comments.List(fileId).Execute();
      return comments.Items;
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Retrieve a list of comments.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to retrieve comments for.
 * @return Array List of Google_Service_Drive_Comment resources.
 */
function retrieveComments($service, $fileId) {
  try {
    $comments = $service->comments->listComments($fileId);
    return $comments->getItems();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library.

from apiclient import errors
# ...

def retrieve_comments(service, file_id):
  """Retrieve a list of comments.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to retrieve comments for.
  Returns:
    List of comments.
  """
  try:
    comments = service.comments().list(fileId=file_id).execute()
    return comments.get('items', [])
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

JavaScript

Uses the JavaScript client library.

/**
 * Retrieve a list of comments.
 *
 * @param {String} fileId ID of the file to retrieve comments for.
 * @param {Function} callback Function to call when the request is complete.
 */
function retrieveComments(fileId, callback) {
  var request = gapi.client.drive.comments.list({
    'fileId': fileId
  });
  request.execute(callback);
}

Try it!

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