Closed AishwaryaMurali closed 4 years ago
did you figure this out? i updated the config but doesnt seem to do much ?
Add this in the .env file
GOOGLE_ALLOW_MULTIPLE_CREDENTIALS=true
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.
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
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.
@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?
Solved it. It's a bad idea just to use a Integer for the setUserId('accountB'). It works when I use a string.
I want to add multiple Gmail accounts in a single Laravel project. How to achieve this?