You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Forms API设置表单访问权限限制?

解决方案:编程创建Google Form并设置访问限制

一、能否通过Google API限制特定邮箱访问表单?

可以,但需通过Google Drive API实现——Google Form本质是存储在Google Drive中的文件,其访问权限由Drive权限系统管控,Forms API本身不直接处理权限设置。具体操作步骤:

  1. 通过Forms API创建表单后,获取返回结果中的formId(该ID即为对应Drive文件的ID)。
  2. 调用Drive API的Permissions.create接口,为特定邮箱添加访问权限:
    • 设置role为reader(只读访问)或writer(可编辑权限)
    • 设置type为user
    • 指定emailAddress为目标邮箱地址
  3. 提前移除表单的公开访问权限(若存在):调用Drive API的Permissions.delete接口,删除type为anyone的权限条目,确保只有指定邮箱能访问。

示例请求(HTTP POST):

POST https://www.googleapis.com/drive/v3/files/{formId}/permissions
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json

{
  "role": "reader",
  "type": "user",
  "emailAddress": "example@domain.com"
}

二、如何设置仅允许同一组织账号访问?

通过Google Drive API结合Forms API的设置,可实现Web UI中“仅限组织内用户”的功能:

  1. 创建表单并获取formId后,先删除所有公开权限(同上一步)。
  2. 调用Drive API添加组织级权限:
    • 设置type为domain
    • 指定domain为你的组织域名(如your-company.com)
    • 设置role为reader
    • 可选设置allowFileDiscovery: false,避免组织内用户通过Drive搜索找到该表单
  3. 调用Forms API的settings.update接口,设置requireLogin为true,强制用户必须登录Google账号才能访问表单,结合Drive的组织权限,确保只有组织内账号可访问。

示例组织权限请求:

POST https://www.googleapis.com/drive/v3/files/{formId}/permissions
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json

{
  "role": "reader",
  "type": "domain",
  "domain": "your-company.com",
  "allowFileDiscovery": false
}

示例设置强制登录:

PATCH https://forms.googleapis.com/v1/forms/{formId}/settings
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json

{
  "requireLogin": true
}

注意:操作前需确保你的API项目已启用Google Drive API和Google Forms API,并获取了包含drive和forms权限的访问令牌。

内容的提问来源于stack exchange,提问作者José C.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 11:50:24