我在 AppEngine 中運(yùn)行了一些相當(dāng)簡(jiǎn)單的 Go 代碼,它們應(yīng)該使用 OAuth2 從用戶(hù)帳戶(hù)中獲取文件列表。似乎可以正常初始化服務(wù),但是當(dāng)它嘗試獲取文件列表時(shí),出現(xiàn)此錯(cuò)誤: OAuthError: RoundTrip: no Token providedpackage fooimport ( "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!")}我無(wú)法弄清楚我在這里做錯(cuò)了什么。任何幫助將不勝感激。
如何在 Go 中的 App Engine 上使用 OAuth2 的客戶(hù)端 ID?
函數(shù)式編程
2021-06-04 18:17:53