使用Google日历API的Web应用程序
我创建了一个简单的Python/Flask网站,该网站通过Google Calendar API连接到Google日历。 I followed the instructions at https://developers.google.com/calendar/api/quickstart /python ,它运行良好...
整个事情对我的公司是内部的。
我将Recorpers.json和Token.json以及我的网站一起复制到我用作Web服务器的内部设备。同样,一切都很好。
除了在某个阶段,我的凭据将会到期,并且Web服务器将需要重新认证我的个人Google帐户。
我该如何解决?
谢谢
I've created a simple Python/flask website which connects to a Google Calendar via the Google Calendar API. I followed the instructions at https://developers.google.com/calendar/api/quickstart/python, and it works well...
The whole thing is internal to my company.
I copied the credentials.json and token.json along with my website to an internal device I'm using as a webserver. Again, all works fine.
Except, at some stage, I am under the impression that my credentials will expire, and the web server will need to re-authenticate with my personal google account.
How do I get around this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的刷新令牌到期的原因是您的应用仍处于测试阶段。在同意屏幕下转到Google Cloud Console,然后将其设置为生产。您的令牌将停止到期。
Web应用程序与已安装的应用程序
您应该注意的是示例
a href =“ https://i.sstatic.net/7ceov.png” rel =“ nofollow noreferrer”>
并为已安装的应用程序使用代码,
因此通过遵循此示例,您没有创建您正在创建已安装的应用程序的Web应用程序。
The reason your refresh token is expiring is that your app is still in the testing phase. Go to google cloud console under the consent screen and set it to production. Your tokens will stop expiring.
web app vs installed app
You should note is the sample you are following states
and uses the code for an installed application
So by following this example you are not creating a web application you are creating an installed application.
使用烧瓶您可以设计以下方案。
/auth
端点,该端点生成授权>
您可以重定向以在Google API中执行授权。/callback
端点。在此回调中,您可以将凭据存储在烧瓶会话中。/auth
。在GCP应用程序控制台中,当您为应用程序创建凭据时,应该选择“ Web应用程序”。

完整代码库: https://github.com/jorzel.com/jorzel/jorzel/jorzel/flask -google-calendar
Using flask you can design the following scheme.
/auth
endpoint that generatesauthorization_url
that you can redirect to perform authorization in Google API./callback
endpoint that handles requests when your authorization in Google API is completed. In this callback, you can store your credentials in a flask session./auth
again.In GCP app console, when you create credentials for your app you should choose "web application".

Full codebase: https://github.com/jorzel/flask-google-calendar
我不知道您是否仍在为此努力。我看到门票已经9个月大了,但最近做了类似的事情,所以我想我会分享。不要使用Google提出的OAUTH2方法。而是:
google_application_credentials = recortentials.json
)calendarid
某处(我将其存储在config.py.py
service = build('valendar','v3')
。该验证是在后台使用此方法完成的。这是一个对我来说很好的示例。使用服务帐户,您无需通过OAuth流量。
I don't know if you are still working on this. I see the ticket is 9 months old but was doing something similar recently so I thought I'd share. Don't use the Oauth2 method that google proposes. Instead:
GOOGLE_APPLICATION_CREDENTIALS=credentials.json
)calendarId
somewhere (I stored it inconfig.py
)service = build('calendar', 'v3')
. The auth is done in the background using this method.Here is an example that works fine for me. With a service account, you don't need to go through the OAuth flow.