升级时的Google Directory API凭据子项

时间:2018-11-24 06:32:26

标签: google-admin-sdk

我正在使用以下代码获取将google成员添加到安全组的权限。

$cred = new Google_Auth_AssertionCredentials(
      $service_account_name,
      array(
      "https://www.googleapis.com/auth/drive",
      "https://www.googleapis.com/auth/drive.file"
      ),
      $key
      );
      $cred->sub = "gaps@aceparking.com";
      }
      else {
        $cred = new Google_Auth_AssertionCredentials(
        $service_account_name,
        array(
        'https://www.googleapis.com/auth/admin.directory.group.member',
        "https://www.googleapis.com/auth/admin.directory.group",
        "https://sites.google.com/feeds/",
        "https://sites.google.com/feeds/acl/"
        ),
        $key
        );
        $cred->sub = "gaps@aceparking.com";
      }
      $client->setAssertionCredentials($cred);
      if ($client->getAuth()->isAccessTokenExpired()) {
        $client->getAuth()->refreshTokenWithAssertion($cred);
      } 

已弃用。我尝试将其作为新代码

    require_once __DIR__ . '../../../protected/vendor/autoload.php';
    $key_file_location = dirname(__FILE__) . '/../extensions/google-api-php-client/GAFW Admin IPI-7ef45aae7f90.p12'; //key.p12
    $key = file_get_contents($key_file_location);
    $dir = dirname(__FILE__).'/../extensions/';
    $client = new Google_Client();
    $credentials_file  = $dir . 'service-account-credentials.json';
    $client->setAuthConfig($credentials_file);
    $client->useApplicationDefaultCredentials();
    $client->setDeveloperKey($key);

但是出现错误: 添加您的帐户时出错

0 个答案:

没有答案