Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
http.authToken = 'ACCESS_TOKEN';
http.accept = 'application/json';
final resp = CkHttpResponse();
try {
http.httpNoBody('GET', 'https://www.googleapis.com/gmail/v1/users/userId/messages', resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Response Status Code: ${resp.statusCode}');
final jsonResponse = CkJsonObject();
jsonResponse.load(resp.bodyStr);
jsonResponse.emitCompact = false;
print(jsonResponse.emit());
if (resp.statusCode != 200) {
print('Failed.');
return;
}
// {
// "messages": [
// users.messages Resource
// ],
// "nextPageToken": string,
// "resultSizeEstimate": unsigned integer
// }
var id = '';
var threadId = '';
final resultSizeEstimate = jsonResponse.intOf('resultSizeEstimate');
var i = 0;
final countI = jsonResponse.sizeOfArray('messages');
while (i < countI) {
jsonResponse.i = i;
id = jsonResponse.stringOf('messages[i].id');
threadId = jsonResponse.stringOf('messages[i].threadId');
i++;
}
}