调用带有base64编码的gmail发送API时,ByteString错误的值无效<或> [英] Invalid value for ByteString error when calling gmail send API with base64 encoded < or >
问题描述
因此,我打电话给Gmail发送邮件API:
https://www.googleapis.com/gmail/v1/users/me/messages/send
我通过在编码的原始消息下面BASE64:
VG86IGVjaG9zaWduLnNmZGMucWFAZ21haWwuY29tDQpTdWJqZWN0OiBSZTogd2UgaGF2ZSBhIGNvb2wgcHJvZHVjdA0KSW4tUmVwbHktVG86IDxDQUFMRnBBSmc1aTJlQ1p4T2dQWlhUdnNaN0J5M0gzNlRCMkNQYTdoVEtzTXh2bXZfT3dAbWFpbC5nbWFpbC5jb20 + DQpSZWZlcmVuY2VzOiA8Q0FBTEZwQUpnNWkyZUNaeE9nUFpYVHZzWjdCeTNIMzZUQjJDUGE3aFRLc014dm12X093QG1haWwuZ21haWwuY29tPg0KDQoxMTozNg = =
解码为:
收件人:echosign.sfdc.qa@gmail.com
主题:Re:我们有一个很酷的产品
In-Reply-To:< CAALFpAJg5i2eCZxOgPZXTvsZ7By3H36TB2CPa7hTKsMxvmv_Ow@mail.gmail.com>
参考文献:< CAALFpAJg5i2eCZxOgPZXTvsZ7By3H36TB2CPa7hTKsMxvmv_Ow@mail.gmail.com>
11:36
我得到这个错误:
状态码:400和状态:错误的请求和响应:{error:{errors:[{domain:global,原因:invalid,message:ByteString的值无效
问题是小于< / code>大于< code>>
In-Reply-To和References标头中的符号,因为我想要我尝试省略<
和>
,但回复然后不线程。
谢谢 如果您正在使用PHP试试这个(否则试着把它转换成你使用的任何语言)
在将mime消息设置为raw属性之前调用下面的函数。
私有函数base64url_encode($ mime){
return rtrim(str tr(base64_encode($ mime),'+ /','-_'),'=');
}
Really stuck on this one and pulling my hair out trying to figure out what to do, searched everywhere and tried everything but still stuck. Any help is much appreciated.
So I am calling the Gmail send message API:
https://www.googleapis.com/gmail/v1/users/me/messages/send
I pass in the following base64 encoded raw message:
VG86IGVjaG9zaWduLnNmZGMucWFAZ21haWwuY29tDQpTdWJqZWN0OiBSZTogd2UgaGF2ZSBhIGNvb2wgcHJvZHVjdA0KSW4tUmVwbHktVG86IDxDQUFMRnBBSmc1aTJlQ1p4T2dQWlhUdnNaN0J5M0gzNlRCMkNQYTdoVEtzTXh2bXZfT3dAbWFpbC5nbWFpbC5jb20+DQpSZWZlcmVuY2VzOiA8Q0FBTEZwQUpnNWkyZUNaeE9nUFpYVHZzWjdCeTNIMzZUQjJDUGE3aFRLc014dm12X093QG1haWwuZ21haWwuY29tPg0KDQoxMTozNg==
Which decodes to:
To: echosign.sfdc.qa@gmail.com
Subject: Re: we have a cool product
In-Reply-To: <CAALFpAJg5i2eCZxOgPZXTvsZ7By3H36TB2CPa7hTKsMxvmv_Ow@mail.gmail.com>
References: <CAALFpAJg5i2eCZxOgPZXTvsZ7By3H36TB2CPa7hTKsMxvmv_Ow@mail.gmail.com>
11:36
I get the error:
Status code: 400 and status: Bad Request and response: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Invalid value for ByteString
The problem is the less than <
and greater than >
symbols in the In-Reply-To and References headers. I need those headers because I am trying to have the email come as a reply on the thread. I tried to leave out the <
and >
but the reply then does not thread.
Thanks
If you are using PHP try this (otherwise try converting it to whatever language you are using)
Call the below function on your mime message before setting it to the raw property.
private function base64url_encode($mime) {
return rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');
}
这篇关于调用带有base64编码的gmail发送API时,ByteString错误的值无效<或>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!