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

如何用Python在指定Google Drive文件夹中创建Google Forms?

解决Google Forms指定目录创建的问题
  • Google Forms API本身不支持创建表单时直接指定父文件夹,你尝试的parents参数不在Forms API的参数列表里,所以无效。
  • 可行的实现方式就是你设想的“先创建再移动”,需要结合Google Drive API完成:
    1. 通过Forms API创建表单后,从返回结果中提取formId,这个ID就是表单在Google Drive中的文件ID。
    2. 调用Drive API的files.update方法,将表单文件添加到目标文件夹中。

示例代码如下:

# 1. 创建表单
form = {
    "info": {
        "title": "My new form"
    },
}
result = form_service.forms().create(body=form).execute()
form_file_id = result["formId"]

# 2. 初始化Drive服务(需确保已完成身份验证)
drive_service = build('drive', 'v3', credentials=credentials)
# 替换为你的目标文件夹ID
target_folder_id = "your_target_folder_id"

# 将表单添加到目标文件夹,若要移除顶层目录,可添加remove_parents='root'参数
drive_service.files().update(
    fileId=form_file_id,
    addParents=target_folder_id
    # remove_parents='root'  # 可选:移除顶层目录的父级
).execute()

如果添加remove_parents='root'参数,表单就只会存在于指定的目标文件夹中,不会保留在Drive顶层目录。

内容的提问来源于stack exchange,提问作者user23202986

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 01:38:17