GPT 操作库:Google 日历

简介

本页面为开发者提供了构建特定应用程序的 GPT 操作的说明和指南。在继续之前,请务必先熟悉以下信息:

此 GPT 操作提供了如何连接到您的Google 日历的概述。它使用 OAuth 连接到您的 Google 帐户,使您能够创建、读取、更新和删除日历中的事件。

价值 + 示例业务用例

价值:用户现在可以利用 ChatGPT 的自然语言功能直接连接到他们的 Google 日历。

示例用例

  • 您想在日历中创建新事件。
  • 您想根据特定条件搜索日历中的事件。
  • 您想从日历中删除事件。

注意: 这是一个很好的 GPT 示例,可以通过 @<您的 GPT 名称> 函数从其他 GPT 调用。您可以在我们的帮助网站上找到有关此功能的更多信息。

应用程序信息

应用程序先决条件

在开始之前,请确保您满足以下先决条件。

  • 拥有 Google 日历访问权限的 Google 帐户。
  • 访问 Google 日历 API 的权限,并使用 Google Cloud Console 配置您的 OAuth 凭据。

Google 日历配置步骤

启用 Google 日历 API

  • 访问 console.cloud.google.com
  • 在项目选择器中,选择您要为此 GPT 操作使用的项目。如果您还没有项目,请点击创建项目按钮。
  • 创建新项目时,请输入项目名称并选择要关联的结算帐户。在此示例中,选择了“无组织”。

现在您有了一个 Google Cloud 项目,可以配置对 Google 日历的 API 访问了。

  • 在快速访问菜单中,选择 API 和服务 >
  • 搜索 Google Calendar API(不是 DKIM)并点击它。
  • 点击启用按钮。

创建 OAuth 凭据

下一步是配置 OAuth 凭据,以允许您的 GPT 操作访问您的 Google 日历。

根据您当前的配置,您可能需要配置您的 OAuth 同意屏幕。我们将从那里开始。

  • 在左侧菜单中点击凭据
  • 现在点击配置同意屏幕
  • 如果出现选项,请选择转到新体验并点击开始
  • 输入您的应用程序名称,并在用户支持电子邮件下拉列表中选择您的电子邮件。
  • 选择内部受众,并输入联系电子邮件。
  • 同意条款并点击创建

我们现在准备创建 OAuth 凭据。

  • 点击创建 OAuth 凭据
  • 选择Web 应用程序
  • 输入您的应用程序名称
  • 在授权的 JavaScript 来源下,输入 https://chat.openai.comhttps://chatgpt.com
  • 目前我们将授权的重定向 URI留空。(稍后我们会回来处理)
  • 点击创建
  • 打开凭据页面,您将在屏幕右侧看到您的 OAuth 客户端 ID 和客户端密钥。

配置 OAuth 范围

接下来,配置 OAuth 客户端 ID 将访问的范围(或服务)。在这种情况下,我们将配置对 Google 日历 API 的访问。

  • 在左侧菜单中点击数据访问
  • 点击添加或删除范围
  • 在右侧面板中筛选 https://www.googleapis.com/auth/calendar
  • 在筛选结果中,选择第一个结果,范围应以 /auth/calendar 结尾
  • 点击更新,然后点击保存

GPT 操作配置步骤

我们现在准备配置 GPT 操作。首先,我们将配置 OAuth 设置,以允许 GPT 与 Google 日历进行身份验证。

  • 在您的 GPT 中创建一个操作。
  • 点击设置齿轮图标并选择 OAuth
  • 输入 Google Cloud Console 中的客户端 ID客户端密钥
  • 输入以下详细信息:
  • 授权 URL:https://accounts.google.com/o/oauth2/auth
  • Token URL:https://oauth2.googleapis.com/token
  • 范围:https://www.googleapis.com/auth/calendar
  • 将 Token Exchange Method 保留为默认值。
  • 点击保存

Google Calendar OAuth

现在我们可以输入操作的 OpenAPI 架构。下面的配置允许读取和创建事件。将其输入到 OpenAPI 架构字段中。

openapi: 3.1.0
info:
  title: Google Calendar API
  description: This API allows you to read and create events in a user's Google Calendar.
  version: 1.0.0
servers:

  - url: https://www.googleapis.com/calendar/v3
    description: Google Calendar API server

paths:
  /calendars/primary/events:
    get:
      summary: List events from the primary calendar
      description: Retrieve a list of events from the user's primary Google Calendar.
      operationId: listEvents
      tags:

        - Calendar
      parameters:

        - name: timeMin
          in: query
          description: The lower bound (inclusive) of the events to retrieve, in RFC3339 format.
          required: false
          schema:
            type: string
            format: date-time
            example: "2024-11-01T00:00:00Z"

        - name: timeMax
          in: query
          description: The upper bound (exclusive) of the events to retrieve, in RFC3339 format.
          required: false
          schema:
            type: string
            format: date-time
            example: "2024-12-01T00:00:00Z"

        - name: maxResults
          in: query
          description: The maximum number of events to return.
          required: false
          schema:
            type: integer
            default: 10

        - name: singleEvents
          in: query
          description: Whether to expand recurring events into instances. Defaults to `false`.
          required: false
          schema:
            type: boolean
            default: true

        - name: orderBy
          in: query
          description: The order of events. Can be "startTime" or "updated".
          required: false
          schema:
            type: string
            enum:

              - startTime
              - updated
            default: startTime
      responses:
        '200':
          description: A list of events
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          description: The event ID
                        summary:
                          type: string
                          description: The event summary (title)
                        start:
                          type: object
                          properties:
                            dateTime:
                              type: string
                              format: date-time
                              description: The start time of the event
                            date:
                              type: string
                              format: date
                              description: The start date of the all-day event
                        end:
                          type: object
                          properties:
                            dateTime:
                              type: string
                              format: date-time
                              description: The end time of the event
                            date:
                              type: string
                              format: date
                              description: The end date of the all-day event
                        location:
                          type: string
                          description: The location of the event
                        description:
                          type: string
                          description: A description of the event
        '401':
          description: Unauthorized access due to missing or invalid OAuth token
        '400':
          description: Bad request, invalid parameters

    post:
      summary: Create a new event on the primary calendar
      description: Creates a new event on the user's primary Google Calendar.
      operationId: createEvent
      tags:

        - Calendar
      requestBody:
        description: The event data to create.
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                summary:
                  type: string
                  description: The title of the event
                  example: "Team Meeting"
                location:
                  type: string
                  description: The location of the event
                  example: "Conference Room 1"
                description:
                  type: string
                  description: A detailed description of the event
                  example: "Discuss quarterly results"
                start:
                  type: object
                  properties:
                    dateTime:
                      type: string
                      format: date-time
                      description: Start time of the event
                      example: "2024-11-30T09:00:00Z"
                    timeZone:
                      type: string
                      description: Time zone of the event start
                      example: "UTC"
                end:
                  type: object
                  properties:
                    dateTime:
                      type: string
                      format: date-time
                      description: End time of the event
                      example: "2024-11-30T10:00:00Z"
                    timeZone:
                      type: string
                      description: Time zone of the event end
                      example: "UTC"
                attendees:
                  type: array
                  items:
                    type: object
                    properties:
                      email:
                        type: string
                        description: The email address of an attendee
                        example: "attendee@example.com"
              required:

                - summary
                - start
                - end
      responses:
        '201':
          description: Event created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: The ID of the created event
                  summary:
                    type: string
                    description: The event summary (title)
                  start:
                    type: object
                    properties:
                      dateTime:
                        type: string
                        format: date-time
                        description: The start time of the event
                  end:
                    type: object
                    properties:
                      dateTime:
                        type: string
                        format: date-time
                        description: The end time of the event
        '400':
          description: Bad request, invalid event data
        '401':
          description: Unauthorized access due to missing or invalid OAuth token
        '500':
          description: Internal server error

如果成功,您将在配置屏幕底部看到这两个端点。

Google Calendar Action Endpoints

设置回调 URL

现在我们已经配置了 OAuth 设置并设置了 OpenAPI 架构,ChatGPT 将生成一个回调 URL。您需要将此 URL 添加到 Google Cloud Console 中的授权的重定向 URI

退出 ChatGPT 中的操作配置屏幕并滚动到底部。在那里,您将找到生成的回调 URL。

注意:如果您修改 OAuth 设置,将生成一个新的回调 URL,这也需要添加到 Google Cloud Console 中的授权的重定向 URI

Google Calendar Callback URL

复制此 URL 并将其添加到 Google Cloud Console 中的授权的重定向 URI,然后点击保存

Google Calendar Callback URL

测试操作

配置好操作后,您现在可以在 ChatGPT 中进行测试。首先向您的 GPT 提出一个测试问题,例如:我今天有什么活动? 如果这是您第一次使用该操作,系统将提示您授权该操作。点击使用 googleapis.com 登录并按照提示授权该操作。

Google Calendar Sign In

授权后,您应该会看到来自您日历的结果。

Google Calendar results