2017-01-18 6 views
0

Можно ли удалить псевдоним пользователя, используя учетную запись службы и Google api?удалить псевдоним, используя google php api

я пытался несколько методов, в том числе:

$optParams = array('alias'=>$userMail); 
    $remove_alias = $directory_service->users->delete($user_info['primaryEmail'],$optParams); 
    $remove1 = $directory_service->getAuth()->authenticatedRequest($remove_alias); 

И

$url = "https://www.googleapis.com/admin/directory/v1/users/" . $user_info['primaryEmail'] . "/aliases/" . $userMail; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $request_headers = array(); 
    $request_headers['Content-type'] = 'application/json'; 

    curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 


    $output = curl_exec($ch); 

    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 
    $header = substr($output, 0, $header_size); 
    $body = substr($output, $header_size); 

    curl_close($ch); 

Я получаю либо сообщение об ошибке 401, необходимо войти в аккаунт. Или ошибка, неидентифицированный псевдоним

ответ

1

Похоже, что вызов пользователей-> удаление vs users_aliases-> delete может вызвать проблему. Может быть, что-то вроде этого будет работать?

require_once $CLIENT_API_PATH . '/vendor/autoload.php'; 
date_default_timezone_set('America/Los_Angeles'); 

// this is the service account json file used to make api calls within the domain 
$serviceAccount = $JSON_PATH . '/service-account-creds.json'; 

// delegate the work to an account with ability to make changes 
$impersonateUser = '[email protected]'; 

// these are the scope(s) used. 
define('SCOPES', implode(' ', array(Google_Service_Directory::ADMIN_DIRECTORY_USER_ALIAS))); 

putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $serviceAccount); 

$client = new Google_Client(); 

// loads the json service account file. 
$client->useApplicationDefaultCredentials(); 
$client->setScopes(SCOPES); 
$client->setSubject($impersonateUser); 

$dirObj = new Google_Service_Directory($client); 

// This is the user account to delete the alias from 
$userKey = '[email protected]'; 
$alias = '[email protected]'; 
$aliasObj = new Google_Service_Directory_Alias(array('alias' => $alias)); 

// delete the alias from the account. 
$results = $dirObj->users_aliases->delete($userKey, $aliasObj); 

// If successful, this method returns an empty response body. 
print_r($results); 

Смотрите также: https://developers.google.com/admin-sdk/directory/v1/reference/users/aliases/delete