2016-07-22 29 views
0

私はGoogle Directory API、oauth2のサービスアカウント、およびPHPをコマンドラインから実行しています。Google Directory APIとPHP:リクエストの不正なクライアントまたはスコープ

最初の手順として、私は単一のユーザーオブジェクトを取得しようとしています。ここでは、コードは次のとおりです。

require_once realpath(__DIR__ . '/../vendor/autoload.php'); 
session_start(); 
define('APPLICATION_NAME', 'Directory API PHP Quickstart'); 
define('SCOPES', implode(' ', 
array(Google_Service_Directory::ADMIN_DIRECTORY_USER_READONLY))); 
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/XXXXXXXX.json'); 
$client = new Google_Client(); 
$client->useApplicationDefaultCredentials(); 
$client->addScope(SCOPES); 
$client->setSubject('[email protected]'); 
$httpClient = $client->authorize(); 
$response = 
$httpClient->get('https://www.googleapis.com/admin/directory/v1/users/[email protected]'); 
print $response->getBody(); 

は、ここで私が得る応答です:管理コンソール>セキュリティで

Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response: 
{ 
"error": "unauthorized_client", 
"error_description": "Unauthorized client or scope in request." 
} 

' in /var/www/feeds/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:107 
Stack trace: #0 /var/www/feeds/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) 
#1 /var/www/feeds/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) 
#2 /var/www/feeds/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) 
#3 /var/www/feeds/vendor/guzzlehttp/promises/src/TaskQueue.php(61): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() 
#4 /var/www/feeds/vendor/guzzlehttp/promis in /var/www/feeds/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 107 

> APIクライアントアクセスを管理し、私はこれらのAPIのスコープとクライアントIDを入力しました:

View and manage the provisioning of groups on your domain 
https://www.googleapis.com/auth/admin.directory.group 
View and manage the provisioning of users on your domain 
https://www.googleapis.com/auth/admin.directory.user 
Groups Settings 
https://www.googleapis.com/auth/apps.groups.settings 

件名( '[email protected]')に使用しているアカウントは、ドメインのスーパー管理者です。ドメイン全体の委任は、サービスアカウントに対して有効になっています。

私はここで何を見落としていますか?どんな助けもありがとう。

答えて

0

管理コンソールでAPIを有効にしていることを確認し、Google Project for Admin SDKでサービスが有効になっているかどうかを確認してください。

関連する問題