This PHP code below has worked for years but since some days ago it has stopped working and I get an error which I show below
The purpose of this code is to update and delete members from the group list in Google Apps.
I searched a lot on Google but couldn't find an answer
Google API client used
https://github.com/googleapis/google-api-php-client
Google Workspace Admin SDK
https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups
PHP CODE
if (isset($_GET['mode']))
$mode = $_GET["mode"];
else
$mode="TASK";
// credentials (with domain delegation)
putenv('GOOGLE_APPLICATION_CREDENTIALS=gaiviweb2web-193e903a022f.json');
// create client
$client = new Google_Client();
// apply credentials
$client->useApplicationDefaultCredentials();
// add scope api
$client->addScope(Google_Service_Directory::ADMIN_DIRECTORY_GROUP);
// impersonate user
$client->setSubject('myemail@mydomain.com');
$client->setUseBatch(true);
$batch = new Google_Http_Batch($client);
// returns a Guzzle HTTP Client
$httpClient = $client->authorize();
// service class
$service = new Google_Service_Directory($client);
$serverName = "myserver";
$connectionInfo = array( "Database"=>"mydb", "UID"=>"myuser", "PWD"=>"mypw");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
$sql = "my_stored_procedure;";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
// get results
while($obj = sqlsrv_fetch_object( $stmt)) {
$lista = $obj->IDGruppo;
$action= $obj->Action;
$email= $obj->Email;
$ragione= $obj->Ragione;
$id= $obj->ID;
// email
$account = array('email' => $email,
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER');
// set member
$member= new Google_Service_Directory_Member($account);
switch($action)
{
case 'ADD':
$request = $service->members->insert($lista, $member);
break;
case 'DEL':
$request = $service->members->delete($lista, $email);
break;
}
// add to batch
$batch->add($request, $id);
// update
if ($mode == 'TASK')
{
$sqlupd = "Update myTable set Process=1 where ID=".$id;
$cmd = sqlsrv_query( $conn, $sqlupd);
}
}
// run
$results = $batch->execute();
echo json_encode($results);
}else{
die( print_r( sqlsrv_errors(), true));
}
ERROR
Fatal error: Uncaught Google_Service_Exception: Error 502 (Server Error)!!1
in C:\mypath\www\src\Google\Http\REST.php on line 118
What can be the problem?