dacastro4 / laravel-gmail

Laravel wrapper for the Gmail API
MIT License
292 stars 134 forks source link

How do I add multiple gmail accounts? #129

Closed AishwaryaMurali closed 4 years ago

AishwaryaMurali commented 4 years ago

I want to add multiple Gmail accounts in a single Laravel project. How to achieve this?

JoshMustafa commented 4 years ago

did you figure this out? i updated the config but doesnt seem to do much ?

blankRSD commented 4 years ago

Add this in the .env file GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true

anvaarkv commented 4 years ago

i have enable multi login from env. but still its not creating more than one json in tokens. unable to save each user file. how can we do this.

dacastro4 commented 4 years ago

The GOOGLE_ALLOW_MULTIPLE_CREDENTIALS key allows having multiple by using the user ID or any kind of ID https://github.com/dacastro4/laravel-gmail/blob/master/src/LaravelGmailClass.php#L11 https://github.com/dacastro4/laravel-gmail/blob/master/src/GmailConnection.php#L27 https://github.com/dacastro4/laravel-gmail/blob/master/src/Traits/Configurable.php#L53

robfrancken commented 4 years ago

I just wanted to add that the default setup assumes 1 token per authorised user. In my case I actually wanted to grant access to multiple Gmail accounts from the same user account. After digging through the code, yes it's possible you just need to manually set the userId:

LaravelGmail::setUserId('accountA')->makeToken();
LaravelGmail::setUserId('accountB')->makeToken();

And then you can access each account separately:

LaravelGmail::setUserId('accountA')->message()->unread()->preload()->all();

@dacastro4 I think this could be added to the README. Happy to send a PR.

ChrisSantiago82 commented 2 years ago

@robfrancken

I'm trying to do the same thing you did. But if I want to access the second account with: LaravelGmail::setUserId('accountB')->makeToken();

I'm getting the access to the first account. Now matter what I do I always access just the first account.

I have set this to true: GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true

How did you do this?

ChrisSantiago82 commented 2 years ago

Solved it. It's a bad idea just to use a Integer for the setUserId('accountB'). It works when I use a string.