我正在使用gmail API搜索郵件。我想包含一些搜索參數,但我無法弄清楚如何使用多個搜索參數。我想這樣做older_than和-unsubscribe使用Gmail API搜索參數
$(document).ready(function() {
var submitButton = 0;
function randomPicture(){
min = Math.ceil(1);
max = Math.floor(14);
var pictureNumber = Math.floor(Math.random() * (max - min)) + min;
$('.sidetext').css('background-image', 'url(images/pic'+pictureNumber+'.jpg)');
console.log(pictureNumber);
}
$('#submit').click(function(){
randomPicture();
var searchTerm = $('#input-person').val();
listMessages('me', searchTerm, listMessageCallback);
submitButton = submitButton + 1;
$('.quote').remove();
});
function listMessages(userId, query, callback) {
$('#content').css('left', $('sidetext'.offsetLeft));
var getPageOfMessages = function(request, result) {
request.execute(function(resp) {
result = result.concat(resp.messages)
};
var initialRequest = gapi.client.gmail.users.messages.list({
'userId': userId,
'q': query
});
// var Request = gapi.client.gmail.users.messages.list({
// 'q': 'older_than:1y'
// });
getPageOfMessages(initialRequest,[]);
}
function listMessageCallback(result){
console.log(result[0].id);
var messageId = result[0].id;
getMessage('me', messageId, getMessageCallback)
}
function getMessageCallback(result){
console.log(result)
$('#content').html(result.snippet);
$('#content').css('font-size', '20px');
$('#content').css('bottom-margin', '0');
// $('#content').app
}
function getMessage(userId, messageId, callback) {
var request = gapi.client.gmail.users.messages.get({
'userId': userId,
'id': messageId,
'nonce': Math.random()
});
request.execute(callback);
}
})
您可以在查詢中使用「AND」,例如, 'older_than:1y AND newer_than:2y' – Tholle