【发布时间】:2021-04-14 22:01:20
【问题描述】:
我的要求是我需要为 Gmail 用户动态添加图像签名。
仅供参考:以下是我遵循的过程
-
在谷歌控制台中创建项目
-
通过以下方式创建 Oauth 客户端 ID
应用类型:网络
授权的 JavaScript 来源:http://localhost
授权重定向 URI:http://localhost:3000
-
下载为 client_request.json
代码如下
'''
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()
creds =None
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:8000/test.png" alt="asaa" width="100" height="100">'}
rsp = GMAIL.users().settings().sendAs().patch(userId='me',
sendAsEmail=address['sendAsEmail'], body=signature).execute()
print("Signature changed to '%s'" % rsp['signature']) '''
我遇到了两个问题:
1) 在我运行上述代码后,它会生成以下 URL
尽管将 3000 指定为重定向端口,但它仍指向 8080
2) 我无法为每个网络请求生成唯一的动态 URL
请提出前进的方向
谢谢
【问题讨论】:
标签: python-3.x google-api google-oauth gmail-api google-api-python-client