[英]Google Calendar API for OAuth Web Application in Python Flask
I have been all over SO and SE looking for the particular answer to this question and cannot seem to find the answer. 我到SO和SE各地都在寻找这个问题的具体答案,但似乎找不到答案。 I am building a simple web application that uses Python Flask to access Google Calendar and fill out the calendar based on conditions.
我正在构建一个简单的Web应用程序,该应用程序使用Python Flask访问Google日历并根据条件填写日历。 My issue is with OAuth2 and getting the redirect_uris correct.
我的问题是OAuth2,并获得正确的redirect_uris。 Below is my code, and every time I try to run my code I get an error that the redirect URI is incorrect and the app will not go any further.
以下是我的代码,每当我尝试运行我的代码时,都会收到一个错误消息,指出重定向URI不正确,该应用程序将无法继续执行。 The redirect uri it seems to be obsessed with is http://localhost:8080 .
似乎迷恋的重定向uri是http:// localhost:8080 。 I have tried setting adding that redirect URI to my developers console, adding that URI with a tailing '/oauth2callback' (with and without a tailing '/').
我尝试设置将重定向URI添加到我的开发人员控制台,并在该URI的末尾添加“ / oauth2callback”(带或不带尾部“ /”)。 I have also tried specifying a different URI entirely, but the error keeps mentioning http://localhost:8080 and never seems to recognize any other redirect URI despite using different client_secret.json files and specifying other uri's in flow_from_client_secrets.
我也尝试过完全指定一个不同的URI,但是该错误不断提及http:// localhost:8080 ,尽管使用了不同的client_secret.json文件并在flow_from_client_secrets中指定了其他uri,但似乎从未识别出任何其他重定向URI。 I have also cleared my cache before running the script every time as well as running things in chrome's incognito mode.
在每次运行脚本以及以chrome隐身模式运行代码之前,我还清除了缓存。 Nothing seems to help.
似乎没有任何帮助。 I know it must be something simple, and if somebody could point out what it was, I would be very appreciative!
我知道这一定很简单,如果有人可以指出它是什么,我将非常感激!
SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_secret_web.json'
APPLICATION_NAME = 'Example Calendar Application'
REDIRECT_URI = 'http://placeholder.com/oauth2callback'
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
redirect_uri=""
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = Storage(credential_path)
credentials = store.get()
flow = client.flow_from_clientsecrets(self.CLIENT_SECRET_FILE,
self.SCOPES, prompt='consent', redirect_uri=self.REDIRECT_URI)
flow.user_agent = self.APPLICATION_NAME
if self.flags:
credentials = tools.run_flow(flow, store, self.flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
我认为您必须删除在〜/ .credentials / calendar-python-quickstart.json中创建的文件,以便程序再次请求权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.