从 Google Apps 中的群组列表更新和删除成员不再工作

问题描述

下面的这段 PHP 代码已经工作多年,但几天前它就停止工作了,我收到一个错误显示在下面
代码的目的是在 Google Apps 的群组列表中更新和删除成员。

我在 Google 上搜索了很多,但找不到答案

使用的 Google Api 客户端
https://github.com/googleapis/google-api-php-client

Google Workspace Admin SDK
https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups

PHP 代码

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('[email protected]');

$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));
}

错误

Fatal error: Uncaught Google_Service_Exception: Error 502 (Server Error)!!1
in C:\mypath\www\src\Google\Http\REST.PHP on line 118

可能是什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)