laravel-gmail icon indicating copy to clipboard operation
laravel-gmail copied to clipboard

Wrong check on isAccessTokenExpired method with GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true

Open phuclh opened this issue 4 years ago • 3 comments

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.

Screen_Shot_2020-12-26_at_11_53_55_AM

phuclh avatar Dec 26 '20 20:12 phuclh

Have you got this issue fixed @phuclh ?

AbithVijayan avatar Jun 10 '21 15:06 AbithVijayan

$gmail = new LaravelGmailClass(config(), 2);

setUserId does not works correctly in facade call

uacode avatar Sep 08 '21 08:09 uacode

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();

andrewtweber avatar Sep 18 '21 01:09 andrewtweber