简体   繁体   中英

can we fetch email from inbox and sentbox in one call (gmail API PHP)

i'm using Gmail API to fetch messages. if i do like this

$labelIds = ['INBOX'];
$opt_params=[
    'labelIds' => $labelIds,
];
$list = $gmail->users_messages->listUsersMessages('me',$opt_params);

it will work fine. and return messages. but if i mention SENT label with INBOX then it return nothing. what am i doing wrong?

$labelIds = ['INBOX', 'SENT'];

i want to fetch emails from both inbox and sentbox in one call.

Your code lists messages that has both the INBOX and SENT labels. You can list messages that has either one with the OR operator:

$opt_params=[
    'maxResults' => 50,
    'q' => 'in:inbox OR in:sent',
];
$list = $gmail->users_messages->listUsersMessages('me', $opt_params);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM