Go Packages support for GSheet Integration
export GSHEET_CREDENTIAL='...'
export GSHEET_TOKEN='...'
- The Spreadsheet ID is the last string of characters in the URL for your spreadsheet. For example, in the URL https://docs.google.com/spreadsheets/d/1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps/edit#gid=0 , the spreadsheet ID is
1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps
.
-
Input URL on web browser to get Authorization Code firstly:
-
Call POST API to retrieve access token:
curl --location 'https://oauth2.googleapis.com/token' \\
--header 'Content-Type: application/x-www-form-urlencoded' \\
--data-urlencode 'grant_type=authorization_code' \\
--data-urlencode 'code={Authorization Code}' \\
--data-urlencode 'client_id={Client ID}' \\
--data-urlencode 'client_secret={Client Secret}' \\
--data-urlencode 'redirect_uri=http://localhost'
package main
import (
"fmt"
"strconv"
"strings"
"github.com/lk153/gsheet-go/lib"
)
func Import() {
srv, err := lib.NewGsheetServiceV2()
if err != nil {
fmt.Println("Cannot connect Gsheet!")
return
}
spreadsheetID := "01c-onQeYHmvc-EPkrJDU-WyAydbCAA1ng6hXCgdYiqqg"
readRange := "'To Update on DB'!A3:AR3"
values := srv.ReadSheet(spreadsheetID, readRange)
for idx, row := range values {
...
...
}
}