Nasi użytkownicy przenieśli się do domeny, do której konta przypisano aliasy. Musieliśmy domyślnie ustawić adres SendAs na jeden z zaimportowanych aliasów i chcieć go zautomatyzować. Interfejs API Gmaila wyglądał jak rozwiązanie, ale nasz uprzywilejowany użytkownik, który ma role do wprowadzania zmian na kontach, nie działał - ciągle widzimy błąd "Odmowa delegacji dla" 403.
Oto przykład PHP, w jaki sposób mogliśmy wyświetlić ich ustawienia SendAs.
<?PHP
//
// Description:
// List the user's SendAs addresses.
//
// Documentation:
// https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs
// https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs/list
//
// Local Path:
// /path/to/api/vendor/google/apiclient-services/src/Google/Service/Gmail.php
// /path/to/api/vendor/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettingsSendAs.php
//
// Version:
// Google_Client::LIBVER == 2.1.1
//
require_once $API_PATH . '/path/to/google-api-php-client/vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
// this is the service account json file used to make api calls within our domain
$serviceAccount = '/path/to/service-account-with-domain-wide-delagation.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $serviceAccount);
$userKey = '[email protected]';
// In the Admin Directory API, we may do things like create accounts with
// an account having roles to make changes. With the Gmail API, we cannot
// use those accounts to make changes. Instead, we impersonate
// the user to manage their account.
$impersonateUser = $userKey;
// these are the scope(s) used.
define('SCOPES', implode(' ', array(Google_Service_Gmail::GMAIL_SETTINGS_BASIC)));
$client = new Google_Client();
$client->useApplicationDefaultCredentials(); // loads whats in that json service account file.
$client->setScopes(SCOPES); // adds the scopes
$client->setSubject($impersonateUser); // account authorized to perform operation
$gmailObj = new Google_Service_Gmail($client);
$res = $gmailObj->users_settings_sendAs->listUsersSettingsSendAs($userKey);
print_r($res);
?>
Ten błąd również zaczął występować u nas. Nie miałem żadnych problemów do tej pory. Jeśli korzystamy z IMAP, wszystko jest w porządku - wygląda na to, że jest problem z interfejsem Gmail API. Pomoc Google? – PNC
Czy to działało wcześniej, czy po prostu się zepsuło? Jeśli po prostu się zepsuł, możesz podać czas, w którym się zepsuł? Jeśli to nigdy nie zadziałało, czy możesz potwierdzić, że jest to konto usługi, umieszczone na białej liście w Cpanel i zapewniające więcej informacji na temat konfiguracji w całej domenie? Używasz czegoś takiego: https://developers.google.com/accounts/docs/OAuth2ServiceAccount#formingclaimset Wyobrażam sobie? –
Czy możesz również opublikować wartość, której używasz w polu "userId" w swoich żądaniach? Czy to "ja", adres e-mail użytkownika, który powinien pasować do tokena uwierzytelnienia lub coś innego? –