【发布时间】:2021-04-16 03:04:51
【问题描述】:
我的要求是我需要根据每个请求动态地授权谷歌用户使用 OAuth2 并以个性化的方式响应。
以下是我遵循的过程##标题##
在谷歌控制台中创建项目
通过以下方式创建 Oauth 客户端 ID
应用类型:网络
授权的 JavaScript 来源:http://localhost
授权重定向 URI:http://localhost:4000
下载为 client_request.json
以下是运行以下python代码后生成的URL,
我们面临的问题是
生成的 URL 在我们无法单独处理每个请求的所有用户中都是相同的。
仅供参考:以下是python代码sn-p
'''
from apiclient import discovery
from googleapiclient.discovery import build
from googleapiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
from oauth2client.tools import argparser, run_flow
args = argparser.parse_args()
from oauth2client.file import Storage
SCOPES = 'https://www.googleapis.com/auth/gmail.settings.basic'
STORAGE = Storage('credentials.storage')
credentials = STORAGE.get()
args.noauth_local_webserver = True
http = httplib2.Http()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, STORAGE,http=http)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
addresses = GMAIL.users().settings().sendAs().list(userId='me',
fields='sendAs(isPrimary,sendAsEmail)').execute().get('sendAs')
for address in addresses:
if address.get('isPrimary'):
break
signature = {'signature':'<img src="https://server:4000/test.png" alt="aaa" width="200" height="200">'}
rsp = GMAIL.users().settings().sendAs().patch(userId='me',
sendAsEmail=address['sendAsEmail'], body=signature).execute()
print("Signature changed to '%s'" % rsp['signature']) '''
【问题讨论】:
-
感谢 Daimto 编辑我的问题
-
我不是 100% 清楚你的问题是什么,或者你想要做什么。
authorize google users using OAuth2 dynamically upon every request and respond in personalized way.是什么意思?
标签: python google-api google-oauth gmail-api google-api-python-client