使用Google API将外部用户添加到G Suite组中

时间:2019-04-14 15:53:24

标签: php google-api google-drive-api gsuite

问题:

企业版Google云端硬盘尚无法将团队驱动器打开到整个Internet。

我不想将文件夹移动到个人磁盘上-与团队驱动器上的团队合作很方便。

我要如何解决该问题:

  1. https://leadstartup.ru/go处有一张表格
  2. 填写此表单后,必须通过API将用户的电子邮件添加到G Suite组中,以便访问Google云端硬盘上的通用云端硬盘。

完成的操作:

  1. 书面课堂,理论上讲应该可以正确解决
use Google_Client;
use Google_Service_Directory;
use Google_Service_Directory_Member;

class GoogleClient
{

    /**
     * Returns an authorized API client.
     * @return Google_Client the authorized client object
     */
    private function getClient()
    {
        $client = new Google_Client();
        $client->useApplicationDefaultCredentials();
        $client->setApplicationName("LeadStartup");
        $client->setScopes([
            Google_Service_Directory::ADMIN_DIRECTORY_GROUP,
            Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER,
            Google_Service_Directory::ADMIN_DIRECTORY_USER
        ]);

        $client->setSubject('a.kolomensky@leadstartup.ru');

        return $client;
    }

    public function addEmailToPublicGroup()
    {
        $member = new Google_Service_Directory_Member();
        $member->setEmail('m.ryazhenka@leadstartup.ru');
        $member->setRole('MEMBER');

        $directory = new Google_Service_Directory($this->getClient());
        $directory->members->insert('friends@leadstartup.ru', $member);
    }
}
  1. 已注册服务帐户

данные сервис-аккаунта

启用了域范围委派。

  1. json文件正确且设置为env
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/private/LeadStartup-8c8edffdb357.json');

json

  1. 合并范围已添加到G Suite

scopes


结果是,我收到401错误 unauthorized_client Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.

请帮我解决这个问题。我想念的是什么?

0 个答案:

没有答案