我正在尝试使用galang.org/x/oauth2包编写一个简单的程序.但我似乎无法交换访问令牌的代码.以下错误有点误导,因为它说已经使用了授权代码,但每次调用登录对话框时我都会看到一个新代码.我是Galang的新手,我可能会犯一个基本的错误,任何指针都会非常有用:)
clientOptions, err = oauth2.New(
oauth2.Client("xxxxxx", "22222222222222"),
oauth2.RedirectURL("http://localhost:3000/auth/cb/fb2"),
oauth2.Scope("public_profile", "email", "user_friends"),
oauth2.Endpoint(
"https://www.facebook.com/dialog/oauth",
"https://graph.facebook.com/oauth/access_token",
),
)
func handleFBSetupOauth(w http.ResponseWriter, r *http.Request) {
url := clientOptions.AuthCodeURL("state", "online", "auto")
fmt.Printf("Visit the URL for the auth dialog: %v", url)
http.Redirect(w, r, url, http.StatusFound)
}
func handleFBOauthCB(w http.ResponseWriter, r *http.Request) (int, string) {
var err error
code := r.FormValue("code")
if code == "" {
return 500, "No code!"
}
fmt.Printf("code - %s", code)
t, err := clientOptions.NewTransportFromCode(code)
if err != nil {
log.Fatal(err)
} …Run Code Online (Sandbox Code Playgroud) 我是golang的新手,我正在尝试获得一个软件包,但是我遇到了一个奇怪的错误,似乎无法弄清楚问题是什么?
padlar@padlar:~/workspace-go$ echo $GOPATH
/home/padlar/workspace-go
padlar@padlar:~/workspace-go$ go get golang.org/x/oauth2
padlar@padlar:~/workspace-go$ ls ~/workspace-go/src/golang.org/x/oauth2/
AUTHORS google/ jwt_test.go README.md
CONTRIBUTORS internal/ LICENSE transport.go
example_test.go jws/ oauth2.go transport_test.go
.git/ jwt.go oauth2_test.go .travis.yml
padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2
oauth2/ oauth2.a
padlar@padlar:~/workspace-go$ ls ~/workspace-go/pkg/linux_amd64/golang.org/x/oauth2/
internal.a jws.a
padlar@padlar:~/workspace-go$ go get github.com/golang/oauth2
can't load package: package github.com/golang/oauth2: code in directory /home/padlar/workspace-go/src/github.com/golang/oauth2 expects import "golang.org/x/oauth2"
Run Code Online (Sandbox Code Playgroud)