【问题标题】:(403) Access Not Configured using Google_Service_Directory(403) 未使用 Google_Service_Directory 配置访问
【发布时间】:2014-09-17 19:45:48
【问题描述】:

当我运行这段代码时:

    $client = new \Google_Client();
    $client->setApplicationName($application_name);
    $client->setClientId($client_id);
    $key = file_get_contents('Google.p12');
    $secret = file_get_contents('Google.json');
    $cred = new \Google_Auth_AssertionCredentials(
            $email_address, array(
        'https://www.googleapis.com/auth/admin.directory.user',
                'https://www.googleapis.com/auth/admin.directory.group'
            ), $key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer');

    $client->setClientSecret($secret);        
    $client->setAssertionCredentials($cred);
    if ($client->getAuth()->isAccessTokenExpired()) {
        $client->getAuth()->refreshTokenWithAssertion($cred);
    }


    $token = $client->getAccessToken();
    $client->setAccessToken($token);

    $this->service = new \Google_Service_Directory($client);


    $adminOptParams = array('domain' => 'mydomain.it');
    $results = $this->service->users->listUsers($adminOptParams);

    foreach ($results as $item) {
        print_r($item);
    }

我收到此错误:

[Google_Service_Exception]
Error calling GET https://www.googleapis.com/admin/directory/v1/users?domai
n=mydomain.it: (403) Access Not Configured. Please use Google Developers C
onsole to activate the API for your project.

请注意,我已经在 Google 应用管理控制台中完成了:

client_id --> 已批准的 api --> https://www.googleapis.com/auth/admin.directory.group https://www.googleapis.com/auth/admin.directory.orgunit https://www.googleapis.com/auth/admin.directory.user

【问题讨论】:

  • 服务帐户是否甚至可以访问 mydomain.it?您是否在云开发者控制台中提供了该应用的产品名称和电子邮件地址?
  • 尝试创建一个新的客户 ID。
  • 你确定你去了 APIs & auths -> APIs 并启用了它?
  • 重新做了一个新的clientID。同样的问题。更改域。同样的问题。好像没有启用API,但是检查没问题。

标签: oauth-2.0 google-api-php-client


【解决方案1】:

在 api 列表中启用 API SDK 以与 App 一起使用。

【讨论】:

    猜你喜欢
    • 2014-12-12
    • 2014-01-22
    • 2014-05-03
    • 1970-01-01
    • 2012-06-12
    • 2013-04-30
    • 1970-01-01
    • 2014-01-24
    • 2013-12-15
    相关资源
    最近更新 更多