Visual FoxPro GMail: Get User's GMail Profile

Back to Index

Gets the current user's Gmail profile.

Documentation: https://developers.google.com/gmail/api/v1/reference/users/getProfile


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loSbJson
LOCAL loJson
LOCAL lcEmailAddress
LOCAL lnMessagesTotal
LOCAL lnThreadsTotal
LOCAL lcHistoryId

loRest = CreateObject('Chilkat_9_5_0.Rest')

*   Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)

lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    CANCEL
ENDIF

loRest.AddPathParam("userId","matt@chilkat.io")

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/gmail/v1/users/userId/profile",loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.LoadSb(loSbJson)

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

lcEmailAddress = loJson.StringOf("emailAddress")
lnMessagesTotal = loJson.IntOf("messagesTotal")
lnThreadsTotal = loJson.IntOf("threadsTotal")
lcHistoryId = loJson.StringOf("historyId")

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loSbJson
RELEASE loJson

Sample JSON Response Body

{
  "emailAddress": "matt@chilkat.io",
  "messagesTotal": 3,
  "threadsTotal": 3,
  "historyId": "1257"
}