【发布时间】:2020-08-25 21:34:43
【问题描述】:
我正在制作一个日历应用程序,它允许用户授予访问他们的谷歌日历的权限,然后我的应用程序将允许他们查看和编辑以我自己的自定义样式显示的日历。
它基于这个谷歌"quickstart" sample。
它目前在本地运行良好,但到目前为止我还没有让它在 pythonanywhere.com 上运行(其中的 URL 将是 http://myname.pythonanywhere.com)。
在我的本地工作版本中,我使用的 credentials.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"
]
}
}
如果我错了,请纠正我,但我假设这个 credentials.json 文件在托管在 myname.pythonanywhere.com 时可能无法工作,我需要创建一个新文件(在 Google 的“API 和服务”上) page) 通过将项目声明为“Web 应用程序”来制作?并告诉谷歌我的重定向 uri 是“http://myname.pythonanywhere.com”?
如果有一种方法可以让单个 credentials.json 文件在本地和 pythonanywhere 上都可以使用?
编辑: 快速入门示例使用InstalledAppFlow.from_client_secrets_file,我现在认为这是错误的。它可能需要以某种方式使用google_auth_oauthlib.flow.Flow.from_client_secrets_file() 来代替......如here 所述。
【问题讨论】:
标签: python flask oauth-2.0 pythonanywhere