Google Drive SDK

Comments: list

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.

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 token to use to request the next page of results.
items[] list List of comments.

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> 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;
  }

  // ...

}

.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>
  /// Drive API service instance.
  /// ID of the file to retrieve comments for.
  /// List of comments.
  public static IList<Comment> RetrieveComments(DriveService service, String fileId) {
    try {
      CommentList comments = service.Comments.List(fileId).Fetch();
      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_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to retrieve comments for.
 * @return Array List of Google_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

Ruby

Uses the Ruby client library

##
# Retrieve a list of comments
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to retrieve comments for
# @return [Array]
#   List of comments
def retrieve_comments(client, file_id)
  drive = client.discovered_api('drive', 'v2')
  api_result = client.execute(
    :api_method => drive.comments.list,
    :parameters => { 'fileId' => file_id })
  if api_result.status == 200
    comments = api_result.data
    return comments.items
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

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.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.