akaramires / laravel-googleforms
Google Forms 的 Laravel 客户端
dev-master
2019-06-24 10:32 UTC
Requires
- php: >=5.6
- google/apiclient: ^1.1
- guzzlehttp/guzzle: 6.*
- illuminate/support: 5.8.*
This package is auto-updated.
Last update: 2024-08-28 15:28:18 UTC
README
安装
使用 composer 安装
composer require akaramires/laravel-googleforms
配置
Google oauth 密钥
-
前往 https://console.cloud.google.com 创建 OAuth 客户端 ID
截图: https://monosnap.com/direct/AvY7Ks2vmUtWkCS2mD8Eukgp3Ad8We -
下载并保存到
storage/
目录中,文件名为google_client_secret.json
截图: https://monosnap.com/direct/OnXeCqQi2UolBrunMLvt5oGK5jG7gv
Laravel
- 发布包配置文件
php artisan vendor:publish --provider="Akaramires\GoogleForms\GoogleFormsServiceProvider"
- 获取访问令牌
php artisan google-forms:token
Google 脚本
- 前往 https://script.google.com
- 创建新项目
- 创建 5 个脚本(脚本内容可在
vendor/akaramires/laravel-googleforms/scripts
目录中找到) - 点击发布 -> 部署为 API 可执行文件
- 复制 API ID 并粘贴到
config/googleforms.php
示例
简单表单
$form = App::make('GoogleForm'); $params = [ 'file_name' => sha1(microtime(true)), 'file_description' => 'File was created by ' . get_current_user() . ' (' . app()->environment() . ')', 'title' => 'Super title', 'description' => 'Super description', 'confirmation_message' => 'Your response has been recorded.', 'show_progress' => false, 'limit_one_response_per_user' => false, 'shuffle_questions' => false, 'show_link_to_respond_again' => false, 'publish_and_show' => false, 'allow_response_edits' => false, 'accepting_responses' => true, ]; $form->createForm($params);
带有字段的表单
$fields = []; $textItem = new TextItem(); // $textItem->setId($field->google_id); # if you have saved field id $textItem->setTitle('Field title'); $textItem->setHelpText('Field help text'); $textItem->setRequired(true); $textItem->setIndex(0); $fields[] = $form->createOrUpdateElement($textItem, true); $queries = [ 'form' => $form->createForm($params, true), 'fields' => $fields, ]; $request = $this->form->batchRequest($queries);; print_r($request);