1

我使用 google 客户端 api 为 ruby​​ 版本 0.7.1 测试电子邮件迁移 API V2 对于分段上传,我总是从服务器收到以下响应:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 503,
  "message": "Backend Error"
 }
}

这是我的代码:

client = Google::APIClient.new(
  :application_name => 'My app',
  :application_version => '1.1.0'
)
#auth code skipped

migration = client.discovered_api('admin', 'email_migration_v2')

file = {"isInbox" => true}
mail =  StringIO.new "Date: Wed, 03 Jan 2013 02:56:03 -0800
From: admin@example.org
To: liz@example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit

And I think to myself... What a wonderful world!"

media = Google::APIClient::UploadIO.new(mail, 'message/rfc822')

client.execute!(:api_method=> migration.mail.insert,
  :media => media,
  :body_object => file,
  parameters: {
    'userKey' => "name@domain.com",
    'uploadType' => 'multipart',
})

一些日志信息

调试 18:58:13 rails [pid=6311]:Google::APIClient::Request 发送 API 请求发布https://www.googleapis.com/upload/email/v2/users/name@domain.com/mail? uploadType=multipart {"User-Agent"=>"My app/1.1.0 google-api-ruby-client/0.7.1 Mac OS X/10.9.4\n (gzip)", "Content-Type"=> "multipart/related;boundary=---------RubyApiMultipartPost", "Content-Length"=>"682", "Accept-Encoding"=>"gzip", "Authorization"=>"Bearer xxxxx", "缓存控制"=>"无存储"}

帖子正文:

DEBUG 18:58:13 rails [pid=6311]: -------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="file.json"
Content-Length: 16
Content-Type: application/json
Content-Transfer-Encoding: binary

{"isInbox":true}
-------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="local.path"
Content-Length: 249
Content-Type: message/rfc822
Content-Transfer-Encoding: binary

Date: Wed, 03 Jan 2013 02:56:03 -0800
From: admin@example.org
To: liz@example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit

And I think to myself... What a wonderful world!
-------------RubyApiMultipartPost--

请帮助我了解为什么 google 会以 503 响应。以及如何解决它。我确定我没有达到 API 配额。

更新1:

看起来 Content-Disposition 标头是 503 错误的原因,因为没有它上传工作正常!

4

0 回答 0