简介
本页面为开发者提供构建特定应用GPT Action的说明与指南。在继续之前,请确保您已熟悉以下信息:
此GPT操作概述了如何连接到您的Google日历。它使用OAuth链接到您的Google账户,使您能够在日历中创建、读取、更新和删除事件。
价值与示例商业应用场景
价值: 用户现在可以利用ChatGPT的自然语言能力直接连接到他们的Google日历。
示例用例:
- 你想在日历中创建一个新事件。
- 您希望根据特定条件在日历中搜索事件。
- 你想从日历中删除一个事件。
注意: 这是一个很好的GPT示例,可能适合通过@功能从其他GPT中调用。您可以在我们的帮助网站上找到有关此功能的更多信息。
应用信息
应用前提条件
在开始之前,请确保您能满足以下先决条件。
- 一个拥有Google日历访问权限的Google账户。
- 访问Google Calendar API并使用Google Cloud Console配置OAuth凭据的权限。
Google日历配置步骤
启用Google日历API
- 访问 console.cloud.google.com。
- 在项目选择器中,选择您想用于此GPT Action的项目。如果还没有项目,请点击创建项目按钮。
- 创建新项目时,请输入项目名称并选择要关联的结算账户。在此示例中,选择了'无组织'。
您现在已拥有一个Google Cloud项目,可以开始配置对Google日历的API访问权限了。
- 在快速访问菜单中,选择 API 和服务 > 库
- 搜索Google Calendar API(不是DKIM)并点击它。
- 点击启用按钮。
创建OAuth凭证
下一步是配置OAuth凭据,以允许您的GPT Action访问您的Google日历。
根据您当前的配置,您可能需要设置OAuth同意屏幕。我们将从这一步开始。
- 在左侧菜单中点击凭证
- 现在点击配置同意屏幕
- 如果出现选项,请选择前往新体验并点击开始使用
- 输入您的应用名称,并在用户支持邮箱下拉菜单中选择您的邮箱。
- 选择内部受众并输入联系邮箱。
- 同意条款并点击创建
我们现在已准备好创建OAuth凭据。
- 点击创建OAuth凭据
- 选择Web应用程序
- 输入您的应用程序名称
- 在"授权JavaScript来源"下,输入
https://chat.openai.com和https://chatgpt.com - 目前我们将暂时将授权重定向URI留空。(稍后会再处理这个)
- 点击创建
- 打开凭据页面,您将在屏幕右侧看到您的OAuth客户端ID和客户端密钥。
配置OAuth范围
接下来,配置OAuth客户端ID将有权访问的作用域(或服务)。在本例中,我们将配置对Google Calendar API的访问权限。
- 在左侧菜单中点击数据访问
- 点击添加或删除权限范围
- 在右侧面板中筛选
https://www.googleapis.com/auth/calendar - 在筛选结果中,选择第一个结果,范围应以
/auth/calendar结尾 - 点击更新然后保存
GPT 操作配置步骤
我们现在准备好配置GPT Action了。首先我们将配置OAuth设置,以允许GPT与Google日历进行身份验证。
- 在你的GPT中,创建一个动作。
- 点击设置齿轮图标并选择OAuth
- 输入来自Google Cloud Console的Client ID和Client Secret。
- Enter the following details:
- 授权URL:
https://accounts.google.com/o/oauth2/auth - 令牌URL:
https://oauth2.googleapis.com/token - 范围:
https://www.googleapis.com/auth/calendar
- 授权URL:
- 将令牌交换方法保持默认设置。
- 点击保存
我们现在可以输入操作的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如果成功,您将在配置屏幕底部看到两个端点出现。
设置回调URL
现在我们已经配置好了OAuth设置并设置了OpenAPI架构,ChatGPT将生成一个回调URL。您需要将此URL添加到Google云控制台中的授权重定向URI中。
退出ChatGPT中的操作配置界面并滚动到底部。在那里,您将找到生成的回调URL。
注意: 如果您修改了OAuth设置,将会生成一个新的回调URL,该URL也需要添加到Google云控制台的授权重定向URI中。
复制此URL并将其添加到Google云控制台中的授权重定向URI,然后点击保存。
测试操作
配置好你的操作后,现在可以在ChatGPT中进行测试。首先向你的GPT提出一个测试问题,例如:What events do I have today? 如果是第一次使用该操作,系统会提示你授权。点击使用googleapis.com登录并按照提示完成操作授权。
授权后,您应该就能看到日历中的结果了。
