google-api-go-client: OAuth & Getting Started instructions do not work
TL;DR: The version of golang.org/x/oauth2
you get from go get
does not work with any of the stated documentation.
1. README.md refers to issuing go get google.golang.org/api/storage/v1
and gives an example of Application Default Credentials. These examples and their docs simply do not work because the version of golang/x/oauth2 etc. that you get with go get
do not contain support for Application Default Credentials’ methods.
- GettingStarted.md’s OAuth HTTP Client instructions points to example code that don’t do any credential handling, but instead refer to a unnamed
registerDemo
that is not findable using GitHub search. Grepping finally finds it inexamples/main.go
. Perhaps the link should go to main.go instead? - GettingStarted.md’s OAuth HTTP Client instructions points to an OAuth config that won’t work, even if you do figure out you need to call
oauth2.Config.AuthCodeUrl
because noRedirectURL
was provided, and unless you’re going to erect a whole new server likeexamples/main.go
does, you need to choose a redirect URI, and the simplest form for a standalone command-line binary isurn:ietf:wg:oauth:2.0:oob
. Finding how to do this was not straightforward. - GettingStarted.md’s OAuth HTTP Client instructions refer to a
newOAuthClient
function that is not of a package, but then doesn’t tell you what package it’s in and has no link. (And actually, it’s not in any package, but is a part ofexamples/main.go
, which you cannot include.)
Finally, GoDoc for golang.org/x/oauth2, golang.org/x/oauth2/google, and even google.golang.api/storage/v1 all refer to newer code than what go get
fetches, so it leads you down the primrose path. Is there a GoDoc docset frozen to what go get
fetches? (e.g., with a version identifier.)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (7 by maintainers)
while we are at it, how about we also include an example for non OAuth api call?
It’s fairly basic, but might really help beginners.
@eladg good idea - not many APIs use this auth mechanism, but would be good to have that in there.