Trying to get a count of labels used in Gmail using Gmail API
I am trying to go one level deeper with the demo code that utilises labels to extract the count of each label used within my inbox. e.g label1 = 5, label2 =10 etc and with a date. Any suggestions?
Demo code:
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
Logger.log('- %s', label.name);
}
}
}
javascript google-apps-script gmail-api
add a comment |
I am trying to go one level deeper with the demo code that utilises labels to extract the count of each label used within my inbox. e.g label1 = 5, label2 =10 etc and with a date. Any suggestions?
Demo code:
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
Logger.log('- %s', label.name);
}
}
}
javascript google-apps-script gmail-api
1
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
I would suggest to take a look at using theUsers.messages:listfunction call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id
– ScottMcC
Nov 22 '18 at 5:32
add a comment |
I am trying to go one level deeper with the demo code that utilises labels to extract the count of each label used within my inbox. e.g label1 = 5, label2 =10 etc and with a date. Any suggestions?
Demo code:
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
Logger.log('- %s', label.name);
}
}
}
javascript google-apps-script gmail-api
I am trying to go one level deeper with the demo code that utilises labels to extract the count of each label used within my inbox. e.g label1 = 5, label2 =10 etc and with a date. Any suggestions?
Demo code:
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
Logger.log('- %s', label.name);
}
}
}
javascript google-apps-script gmail-api
javascript google-apps-script gmail-api
edited Nov 22 '18 at 8:47
Werner Adewole
asked Nov 22 '18 at 0:24
Werner AdewoleWerner Adewole
267
267
1
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
I would suggest to take a look at using theUsers.messages:listfunction call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id
– ScottMcC
Nov 22 '18 at 5:32
add a comment |
1
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
I would suggest to take a look at using theUsers.messages:listfunction call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id
– ScottMcC
Nov 22 '18 at 5:32
1
1
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
I would suggest to take a look at using the
Users.messages:list function call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id– ScottMcC
Nov 22 '18 at 5:32
I would suggest to take a look at using the
Users.messages:list function call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id– ScottMcC
Nov 22 '18 at 5:32
add a comment |
1 Answer
1
active
oldest
votes
Using the Users.messages:list function call from the GMail API should get you your results.
The trick here is to pass label.id to the labelIds argument as a list
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
// Use the label name to get the messages that match this label
var label_messages = Gmail.Users.Messages.list('me', {'labelIds': [label.id]});
Logger.log('%s = %s', label.name, label_messages.resultSizeEstimate);
}
}
}
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422273%2ftrying-to-get-a-count-of-labels-used-in-gmail-using-gmail-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using the Users.messages:list function call from the GMail API should get you your results.
The trick here is to pass label.id to the labelIds argument as a list
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
// Use the label name to get the messages that match this label
var label_messages = Gmail.Users.Messages.list('me', {'labelIds': [label.id]});
Logger.log('%s = %s', label.name, label_messages.resultSizeEstimate);
}
}
}
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
add a comment |
Using the Users.messages:list function call from the GMail API should get you your results.
The trick here is to pass label.id to the labelIds argument as a list
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
// Use the label name to get the messages that match this label
var label_messages = Gmail.Users.Messages.list('me', {'labelIds': [label.id]});
Logger.log('%s = %s', label.name, label_messages.resultSizeEstimate);
}
}
}
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
add a comment |
Using the Users.messages:list function call from the GMail API should get you your results.
The trick here is to pass label.id to the labelIds argument as a list
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
// Use the label name to get the messages that match this label
var label_messages = Gmail.Users.Messages.list('me', {'labelIds': [label.id]});
Logger.log('%s = %s', label.name, label_messages.resultSizeEstimate);
}
}
}
Using the Users.messages:list function call from the GMail API should get you your results.
The trick here is to pass label.id to the labelIds argument as a list
function listLabels() {
var response = Gmail.Users.Labels.list('me');
if (response.labels.length == 0) {
Logger.log('No labels found.');
} else {
Logger.log('Labels:');
for (var i = 0; i < response.labels.length; i++) {
var label = response.labels[i];
// Use the label name to get the messages that match this label
var label_messages = Gmail.Users.Messages.list('me', {'labelIds': [label.id]});
Logger.log('%s = %s', label.name, label_messages.resultSizeEstimate);
}
}
}
answered Nov 22 '18 at 5:48
ScottMcCScottMcC
1,6701318
1,6701318
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
add a comment |
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome that works, thanks ScottMcC!
– Werner Adewole
Nov 22 '18 at 13:44
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
Awesome! If you're happy with my answer, if you could mark it as correct that would be great!
– ScottMcC
Nov 23 '18 at 0:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422273%2ftrying-to-get-a-count-of-labels-used-in-gmail-using-gmail-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

1
Welcome. What is the question? Where did you find the demo? Have you already read developers.google.com/apps-script/overview?
– Rubén
Nov 22 '18 at 1:39
I would suggest to take a look at using the
Users.messages:listfunction call here: developers.google.com/gmail/api/v1/reference/users/messages/… . You could get a list of messages that match a given label Id– ScottMcC
Nov 22 '18 at 5:32