使用 base64 编码 < 调用 gmail 发送 API 时 ByteString 错误的值无效或> [英] Invalid value for ByteString error when calling gmail send API with base64 encoded < or >

查看:17
本文介绍了使用 base64 编码 < 调用 gmail 发送 API 时 ByteString 错误的值无效或>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的坚持这一点,把我的头发拉出来试图弄清楚该怎么做,到处搜索并尝试了所有方法,但仍然卡住了.非常感谢任何帮助.

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.

所以我正在调用 Gmail 发送消息 API:

So I am calling the Gmail send message API:

https://www.googleapis.com/gmail/v1/users/me/messages/发送

我传入以下 base64 编码的原始消息:

I pass in the following base64 encoded raw message:

VG86IGVjaG9zaWduLnNmZGMucWFAZ21haWwuY29tDQpTdWJqZWN0OiBSZTogd2UgaGF2ZSBhIGNvb2wgcHJvZHVjdA0KSW4tUmVwbHktVG86IDxDQUFMRnBBSmc1aTJlQ1p4T2dQWlhUdnNaN0J5M0gzNlRCMkNQYTdoVEtzTXh2bXZfT3dAbWFpbC5nbWFpbC5jb20 + DQpSZWZlcmVuY2VzOiA8Q0FBTEZwQUpnNWkyZUNaeE9nUFpYVHZzWjdCeTNIMzZUQjJDUGE3aFRLc014dm12X093QG1haWwuZ21haWwuY29tPg0KDQoxMTozNg ==

VG86IGVjaG9zaWduLnNmZGMucWFAZ21haWwuY29tDQpTdWJqZWN0OiBSZTogd2UgaGF2ZSBhIGNvb2wgcHJvZHVjdA0KSW4tUmVwbHktVG86IDxDQUFMRnBBSmc1aTJlQ1p4T2dQWlhUdnNaN0J5M0gzNlRCMkNQYTdoVEtzTXh2bXZfT3dAbWFpbC5nbWFpbC5jb20+DQpSZWZlcmVuY2VzOiA8Q0FBTEZwQUpnNWkyZUNaeE9nUFpYVHZzWjdCeTNIMzZUQjJDUGE3aFRLc014dm12X093QG1haWwuZ21haWwuY29tPg0KDQoxMTozNg==

解码为:

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

我得到错误:

状态代码:400 和状态:错误请求和响应:{错误":{错误":[{域":全局",原因":无效",消息":无效值对于字节串

Status code: 400 and status: Bad Request and response: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Invalid value for ByteString

问题在于 In-Reply-To 和 References 标头中的小于 < 和大于 > 符号.我需要这些标题,因为我试图让电子邮件作为线程的回复.我试图省略 <> 但回复没有线程.

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.

谢谢

推荐答案

如果你使用 PHP 试试这个(否则尝试将它转换成你使用的任何语言)

If you are using PHP try this (otherwise try converting it to whatever language you are using)

在将 mime 消息设置为原始属性之前调用以下函数.

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 编码 &lt; 调用 gmail 发送 API 时 ByteString 错误的值无效或&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆