PowerShell
PowerShell
Get a List of Message IDs in GMail User's Mailbox
See more GMail REST API Examples
Demonstrates how to get a list of message IDs in a GMail mailbox. The "userId" can be either the user's email address or the special value "me" to indicate the authenticated user.Chilkat PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$http = New-Object Chilkat.Http
$http.AuthToken = "ACCESS_TOKEN"
$http.Accept = "application/json"
$resp = New-Object Chilkat.HttpResponse
$success = $http.HttpNoBody("GET","https://www.googleapis.com/gmail/v1/users/userId/messages",$resp)
if ($success -eq $false) {
$($http.LastErrorText)
exit
}
$("Response Status Code: " + $resp.StatusCode)
$jsonResponse = New-Object Chilkat.JsonObject
$jsonResponse.Load($resp.BodyStr)
$jsonResponse.EmitCompact = $false
$($jsonResponse.Emit())
if ($resp.StatusCode -ne 200) {
$("Failed.")
exit
}
# {
# "messages": [
# users.messages Resource
# ],
# "nextPageToken": string,
# "resultSizeEstimate": unsigned integer
# }
$resultSizeEstimate = $jsonResponse.IntOf("resultSizeEstimate")
$i = 0
$count_i = $jsonResponse.SizeOfArray("messages")
while ($i -lt $count_i) {
$jsonResponse.I = $i
$id = $jsonResponse.StringOf("messages[i].id")
$threadId = $jsonResponse.StringOf("messages[i].threadId")
$i = $i + 1
}