Uploading Files From Local To Google Drive by Python without Quickstart
This is a sample script for uploading files from local PC to Google Drive using Python. In this sample, Quickstart is not used. So when you use this script, please retrieve access token.
Curl sample :
curl -X POST \
-H "Authorization: Bearer ### access token ###" \
-F "metadata={name : 'sample.png', parents: ['### folder ID ###']};type=application/json;charset=UTF-8" \
-F "file=@sample.png;type=image/png" \
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
]
Python sample :
When above curl sample is converted to Python, it becomes as follows.
Updated ggsrun to v141
ggsrun was updated to v.1.4.1
- v1.4.1 (February 9, 2018)
- For uploading, the resumable-upload method was added.
- The resumable-upload method is automatically used by the size of file.
- “multipart/form-data” can upload files with the size less than 5 MB.
- “resumable-upload” can upload files with the size more than 5 MB.
- The chunk for resumable-upload is 100 MB as the default.
- Users can also give this chunk size using an option.
$ ggsrun u -f filename -chunk 10- This means that a file with filename is uploaded by each chunk of 10 MB.
- The resumable-upload method is automatically used by the size of file.
- For uploading, the resumable-upload method was added.
You can read “How to install” at here.
Copying Values from JSON to Struct using reflect Package
This is a sample script for copying values from JSON to a struct using reflect package.
Script :
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type obj struct {
Key1 string `json:"k1"`
Key2 string `json:"k2"`
Key3 int64 `json:"k3"`
Key4 int `json:"k4"`
Key5 bool `json:"k5"`
}
func main() {
data := `{"k1": "v1", "k2": "v2", "k3": 1234567890, "k4": 456, "k5": true}`
d := map[string]interface{}{}
json.Unmarshal([]byte(data), &d)
obj := &obj{}
s := reflect.ValueOf(obj).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
for j, f := range d {
if typeOfT.Field(i).Tag.Get("json") == j {
fl := s.FieldByName(typeOfT.Field(i).Name)
switch fl.Kind() {
case reflect.Bool:
fl.SetBool(f.(bool))
case reflect.Int, reflect.Int64:
c, _ := f.(float64)
fl.SetInt(int64(c))
case reflect.String:
fl.SetString(f.(string))
}
}
}
}
fmt.Printf("%+v\n", obj) // &{Key1:v1 Key2:v2 Key3:1234567890 Key4:456 Key5:true}
}
Result :
&{Key1:v1 Key2:v2 Key3:1234567890 Key4:456 Key5:true}
The Go Playground
Parsing JSON object (keys are number and changing every time)
This sample script is for parsing JSON object. In the object, the keys are number and changing every time.
Object:
{
"key1": {
"key2": [
{"0": [{"key3": "value3a"}, {"key3": "value3b"}]},
{"1": [{"key3": "value3c"}, {"key3": "value3d"}]}
]
}
}
Script:
package main
import (
"encoding/json"
"fmt"
"strconv"
)
type key1 struct {
Key1 key2 `json:"key1"`
}
type key2 struct {
Key2 []interface{} `json:"key2"`
}
func main() {
data := `{"key1": {"key2": [{"0": [{"key3": "value3a"}, {"key3": "value3b"}]},{"1": [{"key3": "value3c"}, {"key3": "value3d"}]}]}}`
k1 := &key1{}
json.Unmarshal([]byte(data), &k1)
for i, e := range k1.Key1.Key2 {
if key, ok := e.(map[string]interface{})[strconv.Itoa(i)].([]interface{}); ok {
for _, f := range key {
fmt.Printf("%+v\n", f.(map[string]interface{})["key3"])
}
}
}
}
Result:
value3a
value3b
value3c
value3d
The Go Playground
Updated Add-on - RearrangeScripts to v210
Adding a Label to a Message using Message ID for Gmail
These are sample scripts for adding a label to a message using message ID for Gmail.
Sample 1
This sample adds a label to a thread using message ID. In this case, all messages in the thread have the label. Even if it adds a label to a message in the thread using addLabel(), all messages in the thread have the label, becauce addLabel can only be used for the thread.
How to Retrieve Replied Emails for Gmail
Description :
This sample script is for retrieving emails which replied for received mails. Because there are no samples which confirm whether the owner (me) replied to the received mails, I created this. The point is as follows.
- When there are more than 2 messages in a thread, there might be a possibility to have replied.
- For more than 2 messages in a thread
- The email address of “from” for the 1st message is the sender’s address.
- When the email address of “to” of after 2nd messages is the same to that of “from” of 1st one, it is indicates that the thread was replied by owner.
This sample script is made of Google Apps Script (GAS). But also this can be applied to other languages.
Updated: GAS Library - ManifestsApp
ManifestsApp was updated to v1.0.2.
-
v1.0.2 (January 29, 2018)
- ProjectApp2 is published, and got to be able to use both standalone script type and container-bound script type.
- By this, this library also got to be able to be used for the both projects.
- For this update, please enable Apps Script API.
- Please check “How to install”.
- ProjectApp2 is published, and got to be able to use both standalone script type and container-bound script type.
You can check this at https://github.com/tanaikech/ManifestsApp.
GAS Library - ProjectApp2
Overview
This is a GAS project library for Google Apps Script (GAS). This library can be used for the projects of both standalone script type and container-bound script type.
Description
There are Class SpreadsheetApp and Class DocumentApp for operating spreadsheet and document, respectively. But there is no Class for operating GAS project. If there is such Class ProjectApp, GAS project can be directly operated by GAS script. I thought that this will lead to new applications, and created ProjectApp. On the other hand, as a CLI tool for operating GAS project, there has already been ggsrun.
Google OAuth Verification & Application Privacy Policy
Registered Application Name: Workspace & Gemini AI Orchestration Engine
Application Purpose & Core Functionality:
This web page serves as the official homepage and privacy compliance interface for the application "Workspace & Gemini AI Orchestration Engine". This specialized developer utility is designed to research, benchmark, and optimize advanced integrations between Google Workspace services, the Google Apps Script API, and Gemini AI models (via Google Vertex AI / Gemini API endpoints).
The application facilitates automated multi-agent scaffolding, programmatic script deployment, project resource management, and structural analysis of Google Apps Script projects. It allows developers and autonomous AI agents (operating via Model Context Protocol / MCP) to securely evaluate execution performance, implement high-performance batch requests, and test agent-to-agent (A2A) workflows within a controlled and structured environment.
Google User Data Policy Compliance Statements:
1. Data Access & Specific Usage
Our application explicitly requests access to specific Google user accounts through OAuth scopes required strictly for interacting with the Google Apps Script API and Google Workspace endpoints. This access is utilized solely to execute user-initiated or agent-orchestrated programmatic operations—such as creating, modifying, deploying, or benchmarking script projects and executing automated workflows. No background automated extraction occurs without explicit session initiation.
2. Data Storage & Zero-Retention Policy
Adhering to a strict Zero-Retention Model, this application does not store, log, or persist any personal data, OAuth tokens, script source codes, or Google account configurations on any external server, database, or persistent storage medium. All data processing and API responses are handled entirely in-memory or securely on the client side within the active session context, ensuring complete cryptographic transient isolation.
3. Data Sharing & Third-Party Non-Disclosure
We maintain absolute data privacy. No data accessed via Google OAuth scopes is shared, sold, rented, or transferred to third-party entities, advertising networks, or data brokers. All data transmissions are strictly point-to-point, encrypted in transit using industry-standard protocols, and limited entirely to the direct channel between the execution environment and Google's official API gateways.
For inquiries regarding this developer application, technical benchmarks, or verification compliance, please refer to the official documentation and repositories linked on this homepage (tanaikech.github.io).