【发布时间】:2021-10-26 06:59:47
【问题描述】:
我有一个机器人可以检查 gmail 是否有新消息,并向我发送带有文本的通知到电报。我的应用托管在谷歌云上,并在测试模式下运行。根据this answer,OAuth 令牌将在 1 周后过期。我尝试了该答案中提到的所有建议,但没有任何帮助。我只想在服务器上运行我的应用程序。
我尝试创建一个新令牌,但是当我使用它们时,我收到了这个错误:
oauthlib.oauth2.rfc6749.errors.MismatchingStateError: (mismatching_state) CSRF Warning! State not equal in request and response.
我的请求代码:
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', self.SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', self.SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('gmail', 'v1', credentials=creds)
try:
# Do my stuff
text = self.__get_new_msgs_text(service, 'me')
return text
except NotFindException:
raise NotFindException()
【问题讨论】:
标签: python google-api bots gmail-api