laravel-gmail
laravel-gmail copied to clipboard
Wrong check on isAccessTokenExpired method with GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true
I have an application that allows user can create many email accounts to connect to Gmail account, so I set userId is email_account_id instead of authorized user id by default. Something like this:
LaravelGmail::setUserId($emailAccountId)->makeToken()
Then I have a foreach loop to check all email accounts is expired or not:
foreach ($emailAccounts as $emailAccount) {
LaravelGmail::setUserId($emailAccountId)->isAccessTokenExpired()
}
But it just returns the result of the first email account.
Have you got this issue fixed @phuclh ?
$gmail = new LaravelGmailClass(config(), 2);
setUserId does not works correctly in facade call
Not 100% sure but I had a related issue after I switched to multiple credentials. It seems that if the gmail-json.json file still exists, the user ID switching doesn't really work. After I deleted that file (so only the user-specific files e.g. gmail-json-1.json are left), things have been working better
Also, when sending a message, you will have to do something similar and pass the user ID to the Mail constructor
use Dacastro4\LaravelGmail\LaravelGmailClass;
use Dacastro4\LaravelGmail\Services\Message\Mail;
$gmail = new LaravelGmailClass(config(), 2);
if (! $gmail->check()) {
// handle if they are not logged in
}
$mail = (new Mail(null, false, $gmail->userId))->send();