无法使用带有服务帐户的日历 API 生成 google meet 链接

问题描述 投票:0回答:1

我已经创建了服务帐户并能够完成域范围的委派,但它不起作用。我已经在 PHP codeigniter 3 中完成了代码。我使用 google-api-php 版本 2 仍然无法生成 google-meet 链接,但我能够在日历中生成事件。我也向服务帐户授予了日历权限。当我在没有与会者的情况下尝试时,我收到此错误。

当我尝试与与会者一起时,我收到此错误。

这是我完成的示例获取令牌代码

    public function generate_token() {
        $jsonKeyFilePath = APPPATH . 'third_party/gentle-meet-399008-352ca7aa0503.json';
        $serviceAccountEmail = '[email protected]';
        $scopes = [
            'https://www.googleapis.com/auth/calendar',
            'https://www.googleapis.com/auth/admin.directory.resource.calendar',
            'https://www.googleapis.com/auth/calendar.events',
        ];

        $client = new Google_Client();
        $client->setAuthConfig($jsonKeyFilePath);
        $client->setApplicationName('Google Meet');
        $client->setAccessType('offline');
        $client->setScopes($scopes);
        $client->setSubject($serviceAccountEmail);
        if ($client->isAccessTokenExpired()) {
            $token = $client->fetchAccessTokenWithAssertion();
        } else {
            $token = $client->getAccessToken();
        }
        return $token['access_token'];
    }

    public function getRandomId() {
        $characters = 'abcdefghijklmnopqrstuvwxyz';
        $randomString = '';
        for ($i = 0; $i < 8; $i++) {
            $index = rand(0, strlen($characters) - 1);
            $randomString .= $characters[$index];
        }
        return $randomString;
    }

这是我完成的示例插入事件代码

        $accessToken = $this->generate_token();
        $data = array(
            'summary'     => "Testing Meeting",
            'description' => "test",
            'start'       => array(
                'dateTime' => "2023-09-15T20:00:00Z",
                'timeZone' => 'Asia/Kolkata',
            ),
            'end'         => array(
                'dateTime' => "2023-09-15T21:00:00Z",
                'timeZone' => 'Asia/Kolkata',
            ),
            'conferenceData' => array(
                'createRequest' => array(
                    'requestId' => uniqid(),
                    'conferenceSolutionKey' => array(
                        'type' => 'hangoutsMeet',
                    ),
                )
            ),
            'attendees' => array(
                array('email' => '[email protected]'),
            ),
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120);
        curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/calendar/v3/calendars/c8ac70eab58d177ca35596a8be3b8ff0a7489462683a6237ca8bf1ff6bd9dc3e@group.calendar.google.com/events?conferenceDataVersion=1");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            "Content-type: application/json",
            "Accept: application/json",
            "Authorization: Bearer ".$accessToken
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        $result = curl_exec($ch);
        $errors = curl_error($ch);
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $result;

我还附上了域范围授权完成的屏幕截图

这是服务帐户的屏幕截图

这是我分配给该服务帐户的权限的屏幕截图

php codeigniter google-calendar-api service-accounts google-client
1个回答
0
投票
$client->setSubject($serviceAccountEmail);

设置的主题是您希望服务帐户模拟的域中用户的电子邮件。

© www.soinside.com 2019 - 2024. All rights reserved.