Gmail API returns 403 error code and “Delegation denied for

前端 未结 5 1886
礼貌的吻别
礼貌的吻别 2020-11-29 04:58

Gmail API fails for one domain when retrieving messages with this error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
{
  \"code         


        
5条回答
  •  青春惊慌失措
    2020-11-29 06:03

    Our users had migrated into a domain and their account had aliases attached to it. We needed to default the SendAs address to one of the imported aliases and want a way to automate it. The Gmail API looked like the solution, but our privileged user with roles to make changes to the accounts was not working - we kept seeing the "Delegation denied for " 403 error.

    Here is a PHP example of how we were able to list their SendAs settings.

    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);
    
    
    ?>
    

提交回复
热议问题