Open kstmostofa opened 8 months ago
Your code sample is not going to work the way you expected. In order for it to work, you have to save the userID somewhere else, which was generated randomly so that you can retrieve this ID later on (for further requests such as list mails, read mails, etc.)
The package was created to allow multiple credentials; however, quite in a different manner - it supposed that the application that uses the package has multiple users, and thus, it saves the Google API responses in JSON files according to the ID of the currently logged-in user (or whichever other user in that system).
That is logically understandable. However, it left out some edge cases:
The package itself does not acquire any userID from Google response, at least not before executing makeToken(). It is not impossible to modify the sample codes to get the information you need (whatever is necessary to feed the $userID), but I don't want to make things complicated.
The quick dirty "workaround" code is as follows:
Add this line to the makeToken() method in vendor/dacastro4/laravel-gmail/src/GmailConnection.php, under $this->emailAddress = $me->emailAddress;
$this->userId = $this->_config['gmail.allow_multiple_credentials'] ? $me->emailAddress : null;
inside callback() method, you only need to use the basic sample code provided:
LaravelGmail::makeToken();
The code will save response data to a JSON file with a logged-in email address. For eg.; instead of saving to gmail-json-1.json, gmail-json-2.json..., it will save to gmail-json-someone@gmail.com.json; Later on, when calling further methods, you only need to specify the logged in email address as userID, then you are all set.
By pointing out some edge cases above, I also proposed that it is necessary to change the code to archive "true" multiple credentials by using it. Developers will not have to update the package manually for such "tweaks". This is not the perfect solution, it is just the quickest one, because it still leaves the second edge case listed above.
For system with multiple users, the correct way to save response filename should be: gmail-json-(systemUserID)-(loggedInEmailAddress).json
@gnucasher Thanks for your reply I have fixed my issue with a different approach. anyway thanks for your reply
Hi @kstmostofa,
I'm glad to hear that you've resolved your issue with a different approach! I'm always interested in learning new solutions. Would you mind sharing the details of your approach? I'd love to know more about how you tackled the problem.
Thanks, Umar
I am using
setUserId
to set the token but somehow login is not working.below are my code sample
public function callback() { $userId = 'user'. rand(1, 100); LaravelGmail::setUserId($userId)->makeToken(); return redirect()->to('/'); }
Thanks in advance