【发布时间】:2014-12-16 17:35:21
【问题描述】:
通过使用get 和format='raw' 并重新插入它,我成功地克隆了“原始”格式的消息:
params = {'userId':'me", 'id': msg_id, 'format':'raw'}
mesg = service.users().messages().get(**params).execute()
body = {'raw': mesg['raw']}
service.users().messages().insert(userId='me', body=**body).execute()
但我热衷于使用 get 可以通过 format='full' 返回的 json 格式做同样的事情。像这样的:
params = {'userId':'me", 'id': msg_id, 'format':'full'}
mesg = service.users().messages().get(**params).execute()
body = mesg
service.users().messages().insert(userId='me', body=**body).execute()
mesg[1] 的格式见下文。
执行上述操作会给我错误:
HttpError: <HttpError 400 when requesting
https://www.googleapis.com/gmail/v1/users/me/messages?alt=json
returned "
'raw' RFC822 payload message string or uploading message via /upload/*
URL required
">
所以问题是:
我如何通过“完整”json 格式insert 发送消息?
格式是“完整”而不是“原始”,所以我应该使用上传网址吗?如何?
我们是否继续在 raw 或正文中以某种方式使用 json 有效负载?
我们可以将其转换为原始格式然后像以前一样吗?
我是否应该尝试研究如何以这种格式使用upload?
我应该放弃它并使用原始格式吗?
我会听到蟋蟀来回答这个问题吗?
这么多问题。
The messages get documentation is here
The messages insert documentation is here
[1] 完整格式的get 返回这种东西。这就是我希望insert 以某种方式实现的目标。
{u'historyId': u'5226', u'id': u'148af993efc00bce',
u'snippet': u'Hi Joe Get the official Gmail app The best features of Gmail are only available on your phone and',
u'sizeEstimate': 4809, u'threadId': u'148af993efc00bce', u'labelIds': [u'INBOX'],
u'payload': {u'mimeType': u'multipart/alternative', u'headers': [
{u'name': u'MIME-Version', u'value': u'1.0'},
{u'name': u'x-no-auto-attachment', u'value': u'1'},
{u'name':
{u'historyId': u'5226',
u'id': u'148af993efc00bce',
u'snippet': u'Hi Joe Get the official Gmail app The best features of Gmail are only available on your phone and',
u'sizeEstimate': 4809,
u'threadId': u'148af993efc00bce',
u'labelIds': [u'INBOX'], u'payload': {
u'mimeType': u'multipart/alternative',
u'headers': [{u'name': u'MIME-Version',
u'value': u'1.0'}, {
u'name': u'x-no-auto-attachment',
u'value': u'1'},
{u'name': u'Received',
u'value': u'by 10.31.41.213; Thu, 25 Sep 2014 18:35:28 -0700 (PDT)'},
{u'name': u'Date',
u'value': u'Thu, 25 Sep 2014 18:35:28 -0700'},
{u'name': u'Message-ID',
u'value': u'<CAJvL7e8jz9WYNUjHgnmYcyFgySXxjLiH1zjMxOfopURZmAy4iA@mail.gmail.com>'},
{u'name': u'Subject',
u'value': u'The best of Gmail, wherever you are'},
{u'name': u'From',
u'value': u'Gmail Team <mail-noreply@google.com>'},
{u'name': u'To',
u'value': u'Joe Test <test@gmail.com>'},
{u'name': u'Content-Type',
u'value': u'multipart/alternative; boundary=bcaec547c84f9cba4a0503edee6b'}],
u'parts': [{u'mimeType': u'text/plain',
u'headers': [
{u'name': u'Content-Type',
u'value': u'text/plain; charset=UTF-8'},
{
u'name': u'Content-Transfer-Encoding',
u'value': u'quoted-printable'}],
u'body': {
u'data': u'IFRoZSBiZXN0IG9mIEdtYWlsLCB3aGVyZ...
【问题讨论】: