Gets a comment by ID. Try it now or see an example.
Request
HTTP request
GET https://www.googleapis.com/drive/v2/files/fileId/comments/commentId
Parameters
Parameter name | Value | Description |
---|---|---|
Path parameters | ||
commentId |
string |
The ID of the comment. |
fileId |
string |
The ID of the file. |
Optional query parameters | ||
includeDeleted |
boolean |
If set, this will succeed when retrieving a deleted comment, and will include any deleted replies.
(Default: false )
|
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 Comments 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.Comment; import java.io.IOException; // ... public class MyClass { // ... /** * Print information about the specified comment. * * @param service Drive API service instance. * @param fileId ID of the file to print comment for. * @param commentId ID of the comment to print. */ private static void printComment(Drive service, String fileId, String commentId) { try { Comment comment = service.comments().get( fileId, commentId).execute(); System.out.println("Modified Date: " + comment.getModifiedDate()); System.out.println("Author: " + comment.getAuthor()); System.out.println("Content: " + comment.getContent()); } catch (IOException e) { System.out.println("An error occurred: " + e); } } // ... }
.NET
Uses the .NET client library.
using Google.Apis.Drive.v2; using Google.Apis.Drive.v2.Data; using System.Net; // ... public class MyClass { // ... /// <summary>Print information about the specified comment.</summary> /// <param name="service">Drive API service instance.</param> /// <param name="fileId">ID of the file to print comment for.</param> /// <param name="commentId">ID of the comment to print.</param> public static void PrintComment(DriveService service, String fileId, String commentId) { try { Comment comment = service.Comments.Get(fileId, commentId).Execute(); Console.WriteLine("Modified Date: " + comment.ModifiedDate); Console.WriteLine("Author: " + comment.Author); Console.WriteLine("Content: " + comment.Content); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } } // ... }
PHP
Uses the PHP client library.
/** * Print information about the specified comment. * * @param Google_Service_Drive $service Drive API service instance. * @param String $fileId ID of the file to print comment for. * @param String $commentId ID of the comment to print. */ function printComment($service, $fileId, $commentId) { try { $comment = $service->comments->get($fileId, $commentId); print "Modified Date: " . $comment->getModifiedDate(); print "Author: " . $comment->getAuthor()->getDisplayName(); print "Content: " . $comment->getContent(); } catch (Exception $e) { print "An error occurred: " . $e->getMessage(); } }
Python
Uses the Python client library.
from apiclient import errors # ... def print_comment(service, file_id, comment_id): """Print information about the specified comment. Args: service: Drive API service instance. file_id: ID of the file to print comment for. comment_id: ID of the comment to print. """ try: comment = service.comments().get( fileId=file_id, commentId=comment_id).execute() print 'Modified Date: %s' % comment['modifiedDate'] print 'Author: %s' % comment['author']['displayName'] print 'Content: %s' % comment['content'] except errors.HttpError, error: print 'An error occurred: %s' % error
JavaScript
Uses the JavaScript client library.
/** * Print information about the specified comment. * * @param {String} fileId ID of the file to print comment for. * @param {String} commentId ID of the comment to print. */ function printComment(fileId, commentId) { var request = gapi.client.drive.comments.get({ 'fileId': fileId, 'commentId': commentId }); request.execute(function(resp) { console.log('Modified Date: ' + resp.modifiedDate); console.log('Author: ' + resp.author.displayName); console.log('Content: ' + resp.content); }); }
Try it!
Use the APIs Explorer below to call this method on live data and see the response.