SQL Server Google Drive: Creates a New Reply to a Comment

Back to Index

Creates a new reply to a comment. This example creates a reply to a comment on the file having fileId = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw", and commentId = "AAAABg7tSGw".

Documentation: https://developers.google.com/drive/v3/reference/replies/create


CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --   Provide a previously obtained OAuth2 access token.
    DECLARE @oauth2 int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.OAuth2', @oauth2 OUT

    EXEC sp_OASetProperty @oauth2, 'AccessToken', 'OAUTH2_ACCESS_TOKEN'
    EXEC sp_OAMethod @rest, 'SetAuthOAuth2', @success OUT, STR(@oauth2)

    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'www.googleapis.com', 443, 1, 1
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @oauth2
        RETURN
      END

    EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'fields', 'modifiedTime,author,content,action'

    --  The following code creates the JSON request body.
    --  The JSON created by this code is shown below.
    DECLARE @jsonReq int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonReq OUT

    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'content', 'This is the second reply to a comment.'
    EXEC sp_OAMethod @jsonReq, 'UpdateString', @success OUT, 'action', 'resolve'

    DECLARE @sbReq int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbReq OUT

    EXEC sp_OAMethod @jsonReq, 'EmitSb', @success OUT, STR(@sbReq)

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/json'

    DECLARE @sbJson int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbJson OUT

    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies', STR(@sbReq), STR(@sbJson)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @oauth2
        EXEC @hr = sp_OADestroy @jsonReq
        EXEC @hr = sp_OADestroy @sbReq
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END

    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
        PRINT 'Received error response code: ' + @iTmp0

        PRINT 'Response body:'
        EXEC sp_OAMethod @sbJson, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @oauth2
        EXEC @hr = sp_OADestroy @jsonReq
        EXEC @hr = sp_OADestroy @sbReq
        EXEC @hr = sp_OADestroy @sbJson
        RETURN
      END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'LoadSb', @success OUT, STR(@sbJson)

    --  The following code parses the JSON response.
    --  A sample JSON response is shown below the sample code.
    DECLARE @modifiedTime nvarchar(4000)

    DECLARE @authorKind nvarchar(4000)

    DECLARE @authorDisplayName nvarchar(4000)

    DECLARE @authorPhotoLink nvarchar(4000)

    DECLARE @authorMe int

    DECLARE @content nvarchar(4000)

    DECLARE @action nvarchar(4000)

    EXEC sp_OAMethod @json, 'StringOf', @modifiedTime OUT, 'modifiedTime'
    EXEC sp_OAMethod @json, 'StringOf', @authorKind OUT, 'author.kind'
    EXEC sp_OAMethod @json, 'StringOf', @authorDisplayName OUT, 'author.displayName'
    EXEC sp_OAMethod @json, 'StringOf', @authorPhotoLink OUT, 'author.photoLink'
    EXEC sp_OAMethod @json, 'BoolOf', @authorMe OUT, 'author.me'
    EXEC sp_OAMethod @json, 'StringOf', @content OUT, 'content'
    EXEC sp_OAMethod @json, 'StringOf', @action OUT, 'action'


    PRINT 'Example Completed.'

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @oauth2
    EXEC @hr = sp_OADestroy @jsonReq
    EXEC @hr = sp_OADestroy @sbReq
    EXEC @hr = sp_OADestroy @sbJson
    EXEC @hr = sp_OADestroy @json


END
GO

Sample JSON Request Body

{
  "content": "This is the second reply to a comment.",
"action": "resolve"
}

Sample JSON Response Body

{
  "modifiedTime": "2017-11-13T18:25:11.828Z",
  "author": {
    "kind": "drive#user",
    "displayName": "Matt Fausey",
    "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
    "me": true
  },
  "content": "This is the second reply to a comment.",
  "action": "resolve"
}