使用 python 如何将可点击的图像添加为 Gmail 签名

using python how to add clickable image as Gmail Signature

我的要求是使用 python 我们想将图像添加为 gmail 签名。单击图像后,我们要重定向到视频文件。

我手动尝试了此操作,并通过以下步骤成功添加了签名:

  1. 打开 google 文档并上传图片
  2. 添加了图像的超链接
  3. 现在将图片复制到gmail签名部分
  4. 单击图片后,它会成功重定向到视频文件。

使用python,我想以动态方式实现这个

  1. 我创建了 google 驱动器凭据
  2. 启用 google 文档 API
  3. 能够阅读文档数据
  4. 现在,我卡住了如何添加文本作为签名。

我正在尝试以下方法

SCOPES = ['https://www.googleapis.com/auth/gmail.settings.basic','https://www.googleapis.c om/auth/gmail.labels','https://www.googleapis.com/auth/gmail.send']

creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', SCOPES)

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
 rsp = GMAIL.users().settings().sendAs().patch(userId='me',
    sendAsEmail=address['sendAsEmail'], body=DATA).execute()
print("Signature changed to '%s'" % rsp['signature'])

我得到的错误是

"代码": 401, “消息”:“请求缺少必需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据

请提出前进的方向

谢谢 维杰

终于明白了

SCOPES = 'https://www.googleapis.com/auth/gmail.settings.basic'
store = file.Storage('credentials.json')
creds =None
args.noauth_local_webserver = True

if not creds or creds.invalid:

  flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
  creds = tools.run_flow(flow, store,args)
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="http://myserver/mycard.JPG" alt="Trulli" 
  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'])