Google app engine 服务帐户、应用程序引擎、Go、谷歌API

Google app engine 服务帐户、应用程序引擎、Go、谷歌API,google-app-engine,go,google-api,service-accounts,Google App Engine,Go,Google Api,Service Accounts,我尝试使用服务帐户连接到驱动器 事实上我有 c := appengine.NewContext(r) key, err := ioutil.ReadFile("key/key.pem") if err != nil { w.WriteHeader(http.StatusInternalServerError) c.Errorf("Pem file not found") ret

我尝试使用服务帐户连接到驱动器

事实上我有

        c := appengine.NewContext(r)
        key, err := ioutil.ReadFile("key/key.pem")
        if err != nil {
            w.WriteHeader(http.StatusInternalServerError)
            c.Errorf("Pem file not found")
            return
        }
        config := &jwt.Config{
            Email: "xxx@developer.gserviceaccount.com",
            PrivateKey: key,
            Scopes: []string{
                "https://www.googleapis.com/auth/drive",
            },
            TokenURL: google.JWTTokenURL,
        }

        client := config.Client(oauth2.NoContext)
        service, err := drive.New(client)
        if (err != nil) {
            w.WriteHeader(http.StatusInternalServerError)
            c.Errorf("Service connection not works")
            return
        }
        about, err := service.About.Get().Do()
        if (err != nil) {
            w.WriteHeader(http.StatusInternalServerError)
            c.Errorf(err.Error())
            return
        }
        c.Infof(about.Name)
我在这里发现:

当然它不工作,我必须使用urlfetch,但我不知道如何。。。 我得到的错误是
“错误:gethttps://www.googleapis.com/drive/v2/about?alt=json: oauth2:无法获取令牌:Posthttps://accounts.google.com/o/oauth2/token: 不是应用程序引擎上下文“

我该怎么办


谢谢。

谷歌应用程序引擎有两个围棋软件包:
appengine
Google.golang.org/appengine

第一个使用的appengine.Context与oauth2包使用的Context.Context不兼容。您需要将第二个导入到
google.golang.org/appengine

另外,将
client:=config.client(oauth2.NoContext)
更改为
client:=config.client(c)