Gets the current user's Gmail profile.
#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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.AddPathParam(L"userId",L"matt@chilkat.io");
CkStringBuilderW sbJson;
success = rest.FullRequestNoBodySb(L"GET",L"/gmail/v1/users/userId/profile",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 *emailAddress = 0;
int messagesTotal;
int threadsTotal;
const wchar_t *historyId = 0;
emailAddress = json.stringOf(L"emailAddress");
messagesTotal = json.IntOf(L"messagesTotal");
threadsTotal = json.IntOf(L"threadsTotal");
historyId = json.stringOf(L"historyId");
wprintf(L"Example Completed.\n");
}
{
"emailAddress": "matt@chilkat.io",
"messagesTotal": 3,
"threadsTotal": 3,
"historyId": "1257"
}