codeigniter 无法生成谷歌会议链接使用日历API与服务帐户

vzgqcmou  于 8个月前  发布在  其他
关注(0)|答案(1)|浏览(59)

我已经创建了服务帐户,并能够做域广泛的代表团,但它不工作。我用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;

我也附上截图域广泛的代表团做

这里是服务帐户的截图

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

brvekthn

brvekthn1#

$client->setSubject($serviceAccountEmail);

set subject是您希望服务帐户模拟的域中用户的电子邮件。

相关问题