我正在制作一个日历应用程序,它允许用户授予访问其Google日历的权限,然后我的应用程序将允许他们查看和编辑以我自己的自定义样式显示的日历。
基于此Google "quickstart" sample。
目前在本地运行正常,但是到目前为止,在pythonanywhere.com(网址为http://myname.pythonanywhere.com)上托管时,我无法使它运行。
[使用我的工作本地版本,我正在使用的certificate.json文件以"installed":
开头,其AFAICT对应于“桌面应用程序”,并且"redirect_uris":
包含["urn:ietf:wg:oauth:2.0:oob", "http://localhost”]
。 (“ http://localhost”很有意义,但我不知道为什么还有第二个uri“ urn:ietf:wg:oauth:2.0:oob”)
{
"installed": {
"client_id": "XXXXXXXXXXXXXXXX.apps.googleusercontent.com",
"project_id": "my_great_calendar",
"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": "XXXXXXXXXXXXX",
"redirect_uris": [
"urn:ietf:wg:oauth:2.0:oob",
"http://localhost"
]
}
}
如果我错了,请更正我,但是我假设当在myname.pythonanywhere.com上托管时,此certificate.json文件可能无法工作,我需要创建一个新文件(在Google的“ API和服务”页面上将该项目声明为“ Web应用程序”吗?并告诉Google我的重定向uri是“ http://myname.pythonanywhere.com”?
[如果有一种方法可以在本地和pythonanywhere上都可以使用单个凭据。
转到API和服务
redirect_uri
参数来明确指定它:flow = Flow.from_client_secrets_file('client_secrets.json', redirect_uri='http://blah.pythonanywhere.com/')
[要知道要使用哪一个,您可以在启动服务器时通过一些配置(例如环境变量或命令行标志),或者让服务器通过查看主机头自动检测到它。