Comments (2)
package main
import (
"fmt"
"log"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/sheets/v4"
)
//export GOOGLE_APPLICATION_CREDENTIALS=/path/to/my-token.json #before go run
func main() {
client, err := google.DefaultClient(oauth2.NoContext,
"https://www.googleapis.com/auth/devstorage.full_control",
"https://www.googleapis.com/auth/spreadsheets.readonly")
if err != nil {
log.Fatal(err)
}
srv, err := sheets.New(client)
if err != nil {
log.Fatalf("Unable to retrieve Sheets client: %v", err)
}
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
spreadsheetId := "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
readRange := "Class Data!A2:E"
resp, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do()
if err != nil {
log.Fatalf("Unable to retrieve data from sheet: %v", err)
}
if len(resp.Values) == 0 {
fmt.Println("No data found.")
} else {
fmt.Println("Name, Major, Gender:")
for _, row := range resp.Values {
// Print columns A and E, which correspond to indices 0 and 4.
fmt.Printf("%s, %s, %s\n", row[0], row[4], row[1])
}
}
}
from go-samples.
The quickstart wasn't written to use service accounts and, as you discovered, it's a slightly different code path to do so. If you're looking for examples of using service accounts w/Go, there are some instructions on how to do that at the Go client lib -- https://github.com/googleapis/google-api-go-client
from go-samples.
Related Issues (20)
- Golang Gmail Api HOT 4
- Logger Error and how to fix it
- Credentials problem HOT 2
- Error 500: Requested Resource Too Large to Return, responseTooLarge
- token expired and refresh token is not set HOT 1
- Unable to parse client secret file to config: oauth2/google: missing redirect URL in the client_credentials.json exit status 1 HOT 2
- Specify sheet in spreadsheets HOT 1
- Getting Unauthorized HOT 1
- sheets.New() is depricated HOT 1
- don't get token
- Unable to view or download the file uploaded using File.get(File id)
- Feature Request: Manage Group members snippets HOT 1
- "No required module provides package" errors
- Dependency Dashboard
- gmail quickstart.go will not retrieve a token HOT 9
- [SyncRepoSettings bot] - Invalid config file
- Add Calendar Snippets
- Quickstart needs OOB update HOT 1
- Googlesheets Quickstart example unreachable in localhost HOT 3
- Error Malformed auth code HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-samples.