我们可以通过一次通话从收件箱和发件箱中获取电子邮件(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);