Creates a new comment on a file. The file is specified by file ID. This example creates a comment on the file having id = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw".
#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// Provide a previously obtained OAuth2 access token.
CkOAuth2W oauth2;
oauth2.put_AccessToken(L"OAUTH2_ACCESS_TOKEN");
rest.SetAuthOAuth2(oauth2);
success = rest.Connect(L"www.googleapis.com",443,true,true);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
rest.AddQueryParam(L"fields",L"author,content");
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
CkJsonObjectW jsonReq;
jsonReq.UpdateString(L"content",L"This is a test comment about this file...");
CkStringBuilderW sbReq;
jsonReq.EmitSb(sbReq);
rest.AddHeader(L"Content-Type",L"application/json");
CkStringBuilderW sbJson;
success = rest.FullRequestSb(L"POST",L"/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments",sbReq,sbJson);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
if (rest.get_ResponseStatusCode() != 200) {
wprintf(L"Received error response code: %d\n",rest.get_ResponseStatusCode());
wprintf(L"Response body:\n");
wprintf(L"%s\n",sbJson.getAsString());
return;
}
CkJsonObjectW json;
json.LoadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
const wchar_t *authorKind = 0;
const wchar_t *authorDisplayName = 0;
const wchar_t *authorPhotoLink = 0;
bool authorMe;
const wchar_t *content = 0;
authorKind = json.stringOf(L"author.kind");
authorDisplayName = json.stringOf(L"author.displayName");
authorPhotoLink = json.stringOf(L"author.photoLink");
authorMe = json.BoolOf(L"author.me");
content = json.stringOf(L"content");
wprintf(L"Example Completed.\n");
}
{
"content": "This is a test comment about this file..."
}
{
"author": {
"kind": "drive#user",
"displayName": "Matt Fausey",
"photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
"me": true
},
"content": "This is a test comment about this file..."
}