Skip to content

02‐GoogleSheet Preparation

Teeraphat Kullanankanjana edited this page Oct 28, 2023 · 2 revisions

Prerequisite

  1. Google Sheet URL.
  2. Google Sheet Page Name (not the name of file inside the Google Drive).
  3. Google App Script Deployment ID.

Get Google Sheet URL and Page Name

  1. Create your Google Sheet https://docs.google.com/spreadsheets.
  2. Copy the full URL of your sheet (for example: https://docs.google.com/spreadsheets/d/your_google_sheet_id/edit#gid=0).
  3. Copy the name of your page sheet (the default is Sheet1).

Get Google Apps Script Deployment ID

  1. At the Extensions menu, select the Apps Script, and then the new Google Apps Script should be created.
  2. In the Google Apps Script window, copy all of the script from script.gs and paste them into Google Apps Script.
  3. Save the script.
  4. Click the Deploy button, then select New Deployment. After that, the new deployment window should appear.
  5. On the select type menu on the left-side of the window, select Web app
  6. On the configuration menu on the right-side of the window, make sure the scripts are executed by Me (Your Email) and who has access is set to Anyone.
  7. Click Deploy.
  8. Then authorize the aceess with your email (the same email as the owner of google sheet)
  9. If the window shows Google hasn’t verified this app, select the Advanced menu and click Go to <your script name> (unsafe). and continue to authorize the access.
  10. After that, the window will show the Deployment ID.
  11. Copy it.

Verify and Test

After importing your class, create a class instance and put all three credentials into your code.

And don't forget to connect the internet network; otherwise, the code will not work.

# Import Library 
from ggsheet import MicroGoogleSheet
from network import WLAN,STA_IF

# Network Creadential 
ssid = "Change_SSID"    
password = "Change_Password"

# Connect to Network
sta_if = WLAN(STA_IF)
sta_if.active(True)
if not sta_if.isconnected():
   print("Connecting to wifi: ", ssid)
   sta_if.connect(ssid, password)
   while not sta_if.isconnected():
       pass
print("Connection successful")

# Google Sheet Credential 
google_sheet_url = "https://docs.google.com/spreadsheets/d/xxxxxxxxx/edit#gid=0"
google_sheet_name = "Sheet1"
google_app_deployment_id = "xxxxxxxx"

# Create Instance 
ggsheet = MicroGoogleSheet(google_sheet_url,google_sheet_name)
ggsheet.set_DeploymentID(google_app_deployment_id)