GAE中的Django-OAuth2.0重定向到本地主机-授权问题
我对python非常陌生,尤其是应用程序部署。 我的目标是创建一个使用多个Google API并按计划运行的应用程序。出于测试目的,我创建了一个django应用程序,它只是将一行添加到带有当前时间戳的Google工作表中 我为已安装的应用程序创建了Google API凭据,因为我希望此脚本在后台运行。在本地主机上运行应用程序时,一切正常: 我访问触发主脚本的localhost路径,并被重定向到Google身份验证页面。经过授权,我结束了和“你可以关闭这个窗口”页面和测试谷歌表是正确的附加 然而,当我在app Engine上部署应用程序时,我看到了授权屏幕,但在确认后,我被重定向到localhost,并收到警告:“无法访问此站点localhost拒绝连接” 以下是构建Google服务的代码,从主脚本调用:GAE中的Django-OAuth2.0重定向到本地主机-授权问题,django,google-app-engine,google-oauth,google-sheets-api,Django,Google App Engine,Google Oauth,Google Sheets Api,我对python非常陌生,尤其是应用程序部署。 我的目标是创建一个使用多个Google API并按计划运行的应用程序。出于测试目的,我创建了一个django应用程序,它只是将一行添加到带有当前时间戳的Google工作表中 我为已安装的应用程序创建了Google API凭据,因为我希望此脚本在后台运行。在本地主机上运行应用程序时,一切正常: 我访问触发主脚本的localhost路径,并被重定向到Google身份验证页面。经过授权,我结束了和“你可以关闭这个窗口”页面和测试谷歌表是正确的附加 然而,
def createGoogleCreds():
"""Delete token.pickle manually when adding new services."""
scopes = [
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/drive"]
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
print("current", os.getcwd())
if os.path.exists('updateSheet/token.pickle'):
with open('tmp/token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
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(
'tmp/credentials.json', scopes)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('tmp/token.pickle', 'wb') as token:
pickle.dump(creds, token)
sheetService = build('sheets', 'v4', credentials=creds, cache_discovery=False)
gmailService = build('gmail', 'v1', credentials=creds, cache_discovery=False)
driveService = build('drive', 'v3', credentials=creds, cache_discovery=False)
return [sheetService, gmailService, driveService]
和我的凭据.json:
"installed":{
"client_id":"11111-blablalbla.apps.googleusercontent.com",
"project_id":"bb-bi-project",
"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":"blablalbla-blablalbla",
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob:auto", "http://localhost"]}}
但我也尝试从重定向URI中删除localhost,但没有结果
我的目标是开发一个使用GoogleSheets作为界面的应用程序,因此我不确定web应用程序OAuth2.0是否适合我