- Issue created by @RustedBucket
- 🇮🇳India sadashiv
Hi,
I found a similar thing reported at https://stackoverflow.com/questions/34678678/failedprecondition-error-wh...
Can you try that solution i.e. use
$client->setConfig('subject', 'you@email.com');
If that solves the problem then report back so that I can think of some solution . I recommend using client_email from the credentials, if that doesn't work then use the account email and update me which one works, or both fail.
Thanks,
Sadashiv. - 🇺🇸United States RustedBucket
Yep, that seemed to do the trick. Thanks.
Below is my altered code. I just added the line $googleService->googleClient->setConfig('subject', $gmailAddress); Based on your find I also found an old issue from 2016 in the google clients issues that talks about it. https://github.com/googleapis/google-api-php-client/issues/891
Looks like it's an undocumented change to the apis or if it is documented it's buried somewhere. I don't know if it's worth trying to make a "fix" for this vs maybe adding it to the documentation somewhere. Hopefully this is the only gotcha, I started with gmail for what I'm doing because I already had examples that worked. One would think this only applies to the GMail apis but who knows.
And to answer your question about which email I used, it was the email address I'm trying to impersonate so NOT the one from the api credentials since this is intended to pull emails for a user logged into our Drupal.
Thanks for the quick response.
// Would normally be passed into this as a function parameter $gmailAddress = 'some_user@valid_domain.com'; $google_api_service_client = \Drupal::entityTypeManager()->getStorage('google_api_service_client')->load('stored_client_id'); // Get the service. $googleService = \Drupal::service('google_api_service_client.client'); // Set the account. $googleService->setGoogleApiClient($google_api_service_client); // Define subject for impersonation $googleService->googleClient->setConfig('subject', $gmailAddress); // Set optional parameters for the Gmail service $optParams = array( 'labelIds' => 'INBOX', 'q' => '@uncc.edu', 'maxResults' => 10, ); try { $gmail = new \Google_Service_Gmail($googleService->googleClient); $threads = $gmail->users_messages->listUsersMessages($gmailAddress, $optParams); dpm($threads); } catch (Exception $e) { ksm($e); }
- Status changed to Closed: won't fix
almost 2 years ago 2:12pm 24 January 2023 - 🇮🇳India sadashiv
Thanks for updating this info, as you mentioned the email expected is of the end user I can't implement a genarilsed fix and all developers have to handle it in the code.
Thanks,
Sadashiv.