Delphi DLL 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


var
rest: HCkRest;
success: Boolean;
oauth2: HCkOAuth2;
jsonReq: HCkJsonObject;
sbReq: HCkStringBuilder;
sbJson: HCkStringBuilder;
json: HCkJsonObject;
modifiedTime: PWideChar;
authorKind: PWideChar;
authorDisplayName: PWideChar;
authorPhotoLink: PWideChar;
authorMe: Boolean;
content: PWideChar;
action: PWideChar;

begin
rest := CkRest_Create();

//   Provide a previously obtained OAuth2 access token.
oauth2 := CkOAuth2_Create();
CkOAuth2_putAccessToken(oauth2,'OAUTH2_ACCESS_TOKEN');
CkRest_SetAuthOAuth2(rest,oauth2);

success := CkRest_Connect(rest,'www.googleapis.com',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_AddQueryParam(rest,'fields','modifiedTime,author,content,action');

//  The following code creates the JSON request body.
//  The JSON created by this code is shown below.
jsonReq := CkJsonObject_Create();
CkJsonObject_UpdateString(jsonReq,'content','This is the second reply to a comment.');
CkJsonObject_UpdateString(jsonReq,'action','resolve');

sbReq := CkStringBuilder_Create();
CkJsonObject_EmitSb(jsonReq,sbReq);

CkRest_AddHeader(rest,'Content-Type','application/json');

sbJson := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies',sbReq,sbJson);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

if (CkRest_getResponseStatusCode(rest) <> 200) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
    Exit;
  end;

json := CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);

//  The following code parses the JSON response.
//  A sample JSON response is shown below the sample code.

modifiedTime := CkJsonObject__stringOf(json,'modifiedTime');
authorKind := CkJsonObject__stringOf(json,'author.kind');
authorDisplayName := CkJsonObject__stringOf(json,'author.displayName');
authorPhotoLink := CkJsonObject__stringOf(json,'author.photoLink');
authorMe := CkJsonObject_BoolOf(json,'author.me');
content := CkJsonObject__stringOf(json,'content');
action := CkJsonObject__stringOf(json,'action');

Memo1.Lines.Add('Example Completed.');

CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);

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