简体   繁体   English

在 Go 中连接 Google Calendar API 的凭据

[英]Credential to connect the Google Calendar API in Go

I am converting a PHP application to access Google calendar to Go.我正在转换一个 PHP 应用程序以访问 Google 日历到 Go。 I used this step by step to get started.一步一步地开始使用这个。

All went smoothly, but when I run quickstart.go , I get the following error:一切顺利,但是当我运行quickstart.go ,出现以下错误:

Unable to parse client secret file to config: oauth2/google: missing redirect URL in the client_credentials.json exit status 1无法将客户端机密文件解析为配置:oauth2/google:client_credentials.json 退出状态 1 中缺少重定向 URL

Content of the client_secret.json is: client_secret.json内容是:

{  
   "installed":{  
      "client_id":"***********content.com",
      "project_id":"*******",
      "auth_uri":"https://accounts.google.com/o/oauth2/auth",
      "token_uri":"https://accounts.google.com/o/oauth2/token",
      "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
   }
}

That client_secret.json file is located at the root of my GOPATH as instructed in the step by stepclient_secret.json文件位于我的 GOPATH 的根目录中,按照分步说明

I already have a OAuth 2.0 client ID for my PHP app that works just fine in PHP.我的 PHP 应用程序已经有一个OAuth 2.0 client ID ,它在 PHP 中运行良好。 I just want to use that one in the a new Go application to access multiple user calendars, but when I download the json file attached to that ID, I am getting the error above.我只想在新的 Go 应用程序中使用那个来访问多个用户日历,但是当我下载附加到该 ID 的 json 文件时,我收到了上面的错误。 Maybe the quickstart.go is not meant for that usage.也许quickstart.go不适合这种用法。

Any hints?任何提示?

When you create OAuth credentials at https://console.developers.google.com/apis/credentials the dialog initially prompts you to "Configure your OAuth client" and you can choose between "Web application", "Desktop app", etc.当您在https://console.developers.google.com/apis/credentials 上创建 OAuth 凭据时,对话框最初会提示您“配置您的 OAuth 客户端”,您可以在“Web 应用程序”、“桌面应用程序”等之间进行选择。

The client.json obtained for the generated OAuth credentials may not contain a "Return URL", depending on the type chosen initially.根据最初选择的类型,为生成的 OAuth 凭据获取的client.json可能不包含“返回 URL”。

For example, for "Web application" the client.json does not have a redirect URL:例如,对于“Web 应用程序”, client.json没有重定向 URL:

{
  "web": {
    "client_id": "x.apps.googleusercontent.com",
    "project_id": "x",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "x"
  }
}

While for a "Desktop app" it has:而对于“桌面应用程序”,它具有:

{
  "installed": {
    "client_id": "x.apps.googleusercontent.com",
    "project_id": "x",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "x",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "http://localhost"
    ]
  }
}

The Go oauth.google module always requires a return URI: https://github.com/golang/oauth2/blob/0f29369cfe4552d0e4bcddc57cc75f4d7e672a33/google/google.go#L61 Go oauth.google 模块始终需要返回 URI: https : //github.com/golang/oauth2/blob/0f29369cfe4552d0e4bcddc57cc75f4d7e672a33/google/google.go#L61

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM