Lists the messages in the user's mailbox.
#include <C_CkRest.h>
#include <C_CkOAuth2.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkOAuth2 oauth2;
HCkStringBuilder sbJson;
HCkJsonObject json;
int resultSizeEstimate;
int i;
int count_i;
const char *id;
const char *threadId;
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) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
return;
}
sbJson = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/gmail/v1/users/me/messages",sbJson);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
return;
}
if (CkRest_getResponseStatusCode(rest) != 200) {
printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest));
printf("Response body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbJson));
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
return;
}
json = CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
resultSizeEstimate = CkJsonObject_IntOf(json,"resultSizeEstimate");
i = 0;
count_i = CkJsonObject_SizeOfArray(json,"messages");
while (i < count_i) {
CkJsonObject_putI(json,i);
id = CkJsonObject_stringOf(json,"messages[i].id");
threadId = CkJsonObject_stringOf(json,"messages[i].threadId");
i = i + 1;
}
printf("Example Completed.\n");
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
}
{
"messages": [
{
"id": "15fc237e79da4174",
"threadId": "15fc237e79da4174"
},
{
"id": "15fc23688c553739",
"threadId": "15fc23688c553739"
},
{
"id": "15fbd37d3a8f9950",
"threadId": "15fbd37d3a8f9950"
},
{
"id": "15fb5e49b822ac1d",
"threadId": "15fb5e49b822ac1d"
},
{
"id": "15fb5e49b7a0739b",
"threadId": "15fb5e49b7a0739b"
}
],
"resultSizeEstimate": 5
}