我在 AppEngine 中运行了一些相当简单的 Go 代码,应该使用 OAuth2 从用户帐户中获取文件列表。似乎可以初始化服务,但是当它尝试获取文件列表时,出现此错误: OAuthError:RoundTrip:未提供令牌
package foo
import (
"appengine"
"appengine/urlfetch"
"code.google.com/p/goauth2/oauth"
"code.google.com/p/google-api-go-client/drive/v2"
"fmt"
"net/http"
)
var config = &oauth.Config{
ClientId: "(redacted).apps.googleusercontent.com",
ClientSecret: "REDACTED",
Scope: "https://www.googleapis.com/auth/drive",
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
}
func init() {
http.HandleFunc("/", home)
}
func home(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
transport := &oauth.Transport{
Config: config,
Transport: &urlfetch.Transport{Context: c}}
svc, err := drive.New(transport.Client())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
q := svc.Files.List()
_, err = q.Do()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "Success!")
}
我无法弄清楚我在这里做错了什么。任何帮助将不胜感激。