Skip to main content
Chemistry LibreTexts

14.3: Enabling Google Sheets and Obtaining a Key

  • Page ID
    472139
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    In order to connect a sensor to a Google sheet you need to enable a sheet in your Drive and then get a key that your code can use to access the sheet. The key will be in the form of a Json file.

    Enable Google APIs

    1. Go to the Navigation menu/APIs & Services and choose Enabled APIs & services

    clipboard_e1eac4c9ea845eee4a6d838ccc4293f99.pngFigure \(\PageIndex{1}\): Enabling Google APIs, March 2023. (Belford cc 0.0)

    2. Click +ENABLE APIS AND SERVICES.  Note the large selection of APIs and services Google offers

    clipboard_ec474aefd331f6c1d194b7bdf4026fe63.pngFigure \(\PageIndex{2}\): Enabling Google APIs, March 2023. (Belford cc 0.0)

    3. You will need to enable both Google Drive and Google Sheets APIs, and enable both.  These are in the Google Workspace and you may need to click view all (31)

    clipboard_ef986b4c9b9971f54adc54af8bdba3c85.pngFigure \(\PageIndex{3}\): Enabling Google APIs, March 2023. (Belford cc 0.0)

     

    Obtain Key

    1. Go to the Navigation menu/APIs & Services and choose Credentials

    clipboard_e45c447aa9b2bd92b2348f41abfb741db.pngFigure \(\PageIndex{4}\): Creating a key, March 2023. (Belford cc 0.0)

     

    2. Make a new key in the form of a JSON file. To create a JSON file navigate to Credentials. You should see your newly created service account. Click on the edit icon (pencil). Then go to the Keys tab, then click "Add Key" --> "Create new key" 

    clipboard_edd9f48a4882925f8fd0f01e772f510e7.png
    Figure \(\PageIndex{5}\): Creating a key, March 2023. (Belford cc 0.0)

    3. The key will be downloaded to your computer.

    clipboard_e81b081bcebf55769f6389aaab8b97f2f.pngFigure \(\PageIndex{6}\): Creating a key, March 2023. (Belford cc 0.0)

    4. You will want to rename the key and move it to the folder with your Python program that will be using it.

    clipboard_e13e42a0edeb7cc10b91e915a8bfbab5e.pngFigure \(\PageIndex{7}\): Creating a key, March 2023. (Belford cc 0.0)

    Take a look at the json file. Note that it has information related to your project, your account and the authentication service.

    clipboard_ef11fc8397db6afc8d5601c4bbee3ea34.pngFigure \(\PageIndex{8}\): Creating a key, March 2023. (Belford cc 0.0)

    Note, if you go to your credentials you will see that your Service Account for this project has the same email as is in the json file.  In the next step you will create a Google Sheet and share it with this email, so that your Python code that uses the key can upload data through the Google sheet API.

    clipboard_e8f0e64fe39f27784af3f90b32bf6b2b6.pngFigure \(\PageIndex{9}\): Creating a key, March 2023. (Belford cc 0.0)

    Create a Google Sheet

    I suggest you create a folder in your Google Drive for your class projects, that is, your school Google Drive and not the one you used to create this account with.  Right click in that folder and create a new Google Sheet, in this tutorial we will call this "classTest". But you should name it as appropriate to your assignment.  Once you have created the sheet you need to share it with the email associated with your service account.  Be sure to give it editor access.

    clipboard_e22e78e1516344aac291b18228f83bbd3.pngFigure \(\PageIndex{10}\): Creating a key, March 2023. (Belford cc 0.0)

    You should now be ready to write some code that will allow you to upload data to the Google Sheet in real time.


    This page titled 14.3: Enabling Google Sheets and Obtaining a Key is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?