Google Drive SDK

Replies: insert

Creates a new reply to the given comment. Try it now or see an example.

Request

HTTP request

POST https://www.googleapis.com/drive/v2/files/fileId/comments/commentId/replies

Parameters

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

Request body

In the request body, supply a Replies resource with the following properties:

Property name Value Description Notes
Optional Properties
content string The plain text content used to create this reply. This is not HTML safe and should only be used as a starting point to make edits to a reply's content. This field is required on inserts if no verb is specified (resolve/reopen). writable
verb string The action this reply performed to the parent comment. When creating a new reply this is the action to be perform to the parent comment. Possible values are:
  • "resolve" - To resolve a comment.
  • "reopen" - To reopen (un-resolve) a comment.


Acceptable values are:
  • "reopen":
  • "resolve":
writable

Response

If successful, this method returns a Replies resource in the response body.

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.CommentReply;

import java.io.IOException;
// ...

public class MyClass {

  // ...

  /**
   * Insert a new reply to a comment.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to insert reply for.
   * @param commentId ID of the comment to insert reply for.
   * @param content Text content of the reply.
   * @return The inserted reply if successful, {@code null} otherwise.
   */
  private static CommentReply insertReply(Drive service, String fileId,
      String commentId, String content) {
    CommentReply newReply = new CommentReply();
    newReply.setContent(content);
    try {
      return service.replies().insert(fileId, commentId, newReply).execute();
    } 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.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Insert a new reply to a comment.
  /// </summary>
  /// Drive API service instance.
  /// ID of the file to insert reply for.
  /// ID of the comment to insert reply for.
  /// Text content of the reply.
  /// The inserted reply, null is returned if an API error occurred
  public static CommentReply InsertReply(
      DriveService service, String fileId, String commentId, String content) {
    CommentReply newReply = new CommentReply();
    newReply.Content = content;
    try {
      return service.Replies.Insert(newReply, fileId, commentId).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library

/**
 * Insert a new reply to a comment.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to insert reply for.
 * @param String $commentId ID of the comment to insert reply for.
 * @param String $content Text content of the reply.
 * @return Google_Comment The inserted reply. NULL is returned if an API
 *                        error occurred.
 */
function insertReply($service, $fileId, $commentId, $content) {
  $newReply = new Google_CommentReply();
  $newReply->setContent($content);
  try {
    return $service->replies->insert($fileId, $commentId, $newReply);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library

from apiclient import errors
# ...

def insert_reply(service, file_id, comment_id, content):
  """Insert a new reply to a comment.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to insert reply for.
    comment_id: ID of the comment to insert reply for.
    content: Text content of the reply.
  Returns:
    The inserted reply if successful, None otherwise.
  """
  new_reply = {
      'content': content
  }
  try:
    return service.replies().insert(
        fileId=file_id, commentId=comment_id, body=new_reply).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

Ruby

Uses the Ruby client library

##
# Insert a new reply to a comment
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to insert reply for
# @param [String] comment_id
#   ID of the comment to insert reply for
# @param [String] content
#   Text content of the reply
# @return [Google::APIClient::Schema::Drive::V2::Reply]
#   The inserted reply if successful, nil otherwise
def insert_reply(client, file_id, comment_id, content)
  drive = client.discovered_api('drive', 'v2')
  new_reply = drive.replies.insert.request_schema.new({
    'content' => content
  })
  result = client.execute(
    :api_method => drive.replies.insert,
    :body_object => new_reply
    :parameters => {
      'fileId' => file_id,
      'commentId' => comment_id
    })
  if result.status == 200
    return result.data
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Insert a new reply to a comment.
 *
 * @param {String} fileId ID of the file to insert reply for.
 * @param {String} commentId ID of the comment to insert reply for.
 * @param {String} content Text content of the reply.
 */
function insertReply(fileId, commentId, content) {
  var body = {'content': content};
  var request = gapi.client.drive.replies.insert({
    'fileId': fileId,
    'commentId': commentId,
    'resource': body
  });
  request.execute(function(resp) { });
}

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.