2016-09-25 6 views
0

내가 인증에 올 때까지 인증 구글 시트 API V4/REST와/이동

모든 위대한 구글

에서 예를 https://developers.google.com/sheets/reference/rest/v4/spreadsheets.values/update을 읽었습니다. 나는 Golang에서 내 응용 프로그램에서 스프레드 시트를 업데이트하려면이 PUT 요청을 보내 싶습니다

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) 

응답 내가 Auth Guide을 파악하려고

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

하지만 솔직히 내가 생각 확실하지 않다 어떻게 요청을 인증 할 수 있겠습니까? 도움이 될 것입니다.

답변

0

키는 공용 데이터에 액세스하는 데 사용되며 Oauth2에서는 응용 프로그램에서 개인 데이터에 액세스 할 수있는 권한을 인증하고 부여해야합니다.

V3에서 작업 한 경우 : 공개 키에 액세스하려는 Google 시트를 설정할 수 있으며 작동 할 수 있습니다.

그렇지 않으면 Oauth2를 구현해야합니다. 내가 도와 줄 수 있지만 Google에 대한 빠른 검색 Oauth2 자습서의 무리가 나타났다.

업데이트 : 방금 ​​문서를 확인했습니다. 날 리드 Method: spreadsheets.values.update

Authorization 

Requires one of the following OAuth scopes: 

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

들은 API의 V4에서 공용 트릭을 제거 있다고 생각합니다. oauth2 또는 서비스 계정을 구현해야하는 것 같습니다.

+0

실제로 시트는 공개되어 있으므로 등록 할 필요가 없습니다. 여전히 동일한 결과가 나타납니다. – MikeKlemin

+0

공개 인증이 필요한 문서는 작동하지 않습니다. – DaImTo

+0

새로 고침 토큰 등 모든 것을 관리하기 때문에 Go API를 사용할 것이라고 생각합니다. 다소 복잡 할 것입니다. 나는 Put request의 단순함을 좋아할 것이다. – MikeKlemin