无法在服务器上使用谷歌登录,但在本地主机上正常工作。

huangapple go评论88阅读模式
英文:

Couldn't login using google on server but works fine on localhost

问题

我已经将Google日历集成到客户端中,客户端需要先登录他们的Google账户。
在本地主机上一切正常,但在服务器上重定向到Google账户没有发生。我尝试查找了这个问题并找到了一些解决方案,但无法理解并在我的端上实施在服务器上运行的解决方案。

文档链接: https://developers.google.com/calendar/api/quickstart/python

这是用于Google登录的主要代码:

flow = InstalledAppFlow.from_client_secrets_file('google_calendar_client_python.json', self.scope)
self.creds = flow.run_local_server(port=0)

现在我明白了在 "flow.run_local_server(port=0)" 中存在一些问题,它只在本地主机上运行,但我找不到任何解决方案来使其在服务器上运行。

如果您能帮忙,我将不胜感激。

附言:如果有人需要完整的代码,我会贴出来!

英文:

I have integrated google calendar in which client needs to login to their google account first.
Everything works fine on local host but on server redirection for google account is not happening. I tried to look for this issue and have found some solution but couldn't undestand and implement that on my end that works on server.

Documentation: https://developers.google.com/calendar/api/quickstart/python

This is the main code that is used for google sign in:

flow = InstalledAppFlow.from_client_secrets_file('google_calendar_client_python.json', self.scope)
self.creds = flow.run_local_server(port=0)

Now I understand that there is some issue in "flow.run_local_server(port=0)" that works only on local host but I couldn't find any solution for this to make it work on server

Please help if you can.

P.S: Will post full code if anybody wants that!

答案1

得分: 1

InstalledAppFlow.from_client_secrets_file('google_calendar_client_python.json') 是为安装的应用程序设计的,它在运行代码的计算机上打开 Web 同意表单。

由于它将在 Web 服务器上打开,因此在托管环境中它不会工作。您需要使用 Web 认证代码,我通常个人使用 Flask。

是的,Google Python 客户端支持它,只是文档不是很详细。

英文:

InstalledAppFlow.from_client_secrets_file('google_calendar_client_python.json is intended for installed applications it opens the web consent form on the machine the code is running on.

it won't work hosted as it's going to open it on the web server. You need to use web authentication code I normally use flask personally

yes the google python client supports it its just not very well documented

huangapple
  • 本文由 发表于 2023年7月20日 16:26:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定