使用Google Sheets API V4 / REST / Go进行身份验证

I have read example https://developers.google.com/sheets/reference/rest/v4/spreadsheets.values/update from Google

Everything is great until I coming to authentication. I would like to send this Put request to update a spreadsheet from my application from Golang:

key := "my key"
// I think I do not need key, because it have to be OAuth... 
spreadsheetId := "myspreadsheetID"
link := fmt.Sprintf("https://sheets.googleapis.com/v4/spreadsheets/%s/values/A1?valueInputOption=RAW&fields=updatedCells&key=%s",
spreadsheetId, key)

request := gorequest.New()
resp, body, errs := request.Put(link).
    Send(`{"values": [ ["hello","my", "friends" ] ]}`).
    End()

if errs != nil {
    fmt.Println(errs)
}

if resp.StatusCode != 200 {
    fmt.Println(resp.Status)

}

fmt.Println(body)

The response is

401 Unauthorized
{
 "error": {
 "code": 401,
 "message": "The request does not have valid authentication credentials.",
 "status": "UNAUTHENTICATED"
 }
}

I tried to grasp the Auth Guide but honestly I am not sure I figured out how can auth the request... Any help would be appreciated very much.

Key is used for accessing Public data, Oauth2 requires that you authenticate and grant the application permission to access private data.

Worked in V3: If you want to use a key you can set the google sheet you are trying to access public and it will work.

Otherwise you are going to have to implement Oauth2. I cant help with go but a quick search on google turned up a bunch of Oauth2 tutorials for it.

Update: I just did a quick check in the documentation. Method: spreadsheets.values.update

Authorization

Requires one of the following OAuth scopes:

* https://www.googleapis.com/auth/drive
* https://www.googleapis.com/auth/spreadsheets

which leads me to think that they removed the public trick from the v4 of the api. Looks like you are going to have to implement oauth2 or service accounts