Skip to content

lk153/gsheet-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference MultiPlatformUnitTest reviewdog Gosec

Coverage Coverage Status Go Report Card

Gsheet Utils

Go Packages support for GSheet Integration

1. Setup ENV

export GSHEET_CREDENTIAL='...'
export GSHEET_TOKEN='...'

2. Additional Information

3. Get Gsheet Credential

Reference

4. Get Gsheet Token

  1. Input URL on web browser to get Authorization Code firstly:

    https://accounts.google.com/o/oauth2/auth?state-token=offline&redirect_uri=http://localhost&response_type=code&client_id={client_id}&scope=https://www.googleapis.com/auth/spreadsheets

  2. 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'

5. Code Examples:

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 {
            ...
            ...
	}
}

About

Go Packages for GSheet Utility

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published