0
サービスアカウントを作成し、クライアントIDにスコープhttps://www.googleapis.com/auth/admin.directory.group
を指定しました。次のコードを実行すると、403エラーが発生します。Google Admin SDK取得403不十分なアクセス許可エラー
<?php
// Requires >= PHP 5.4
require_once(__DIR__ . '/vendor/autoload.php');
date_default_timezone_set('America/Chicago');
$settings = [
'creds_path' => '/path/to/service_creds.json',
'group_email' => '[email protected]',
'service_email' => '[email protected]'
];
putenv("GOOGLE_APPLICATION_CREDENTIALS={$settings['creds_path']}");
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Directory::ADMIN_DIRECTORY_GROUP);
// $client->setSubject('[email protected]');
$service = new Google_Service_Groupssettings($client);
try {
print_r($service->groups->get($settings['group_email'], ['alt' => 'json']));
} catch(Google_Service_Exception $e) {
if($e->getCode() == 404) {
echo "Group {$settings['group_email']} not found.\n";
exit;
} elseif($e->getCode() == 403) {
echo "Insufficient Permissions.\n";
exit;
} else {
throw $e;
}
}
私は、サービスアカウントが管理者のSDKへのアクセス権を持っている人を偽装する必要があることをどこかで読んので、それはコメントアウト行が試したものだが、それは動作しませんでした。
何が間違っているのか分かりますか?
required
ているのコードは、それは私が間違ったクラスを使用していたということになったhttps://github.com/google/google-api-php-client