0

我有一个与 Microsoft Outlook 帐户同步的应用程序。早在昨晚它就工作得很好,但最近遇到了一个问题:每次我进行 API 调用时都会收到此错误:

{"error"=>{"code"=>"MailboxInfoStale", "message"=>"Mailbox info is stale."}}

我知道我正在测试的邮箱不是陈旧的,因为它在不到一个小时前被访问和使用过。这是我的代码:

# Get the emails between the user and the prospect
# We need to be aware of the user's MS email address, which is possible different than the one we have
# for them.

user_email = user_email || get_user_email(token, context)

if token
  conn = Faraday.new(:url => "https://outlook.office.com") do |faraday|
    faraday.response :logger
    faraday.adapter Faraday.default_adapter
  end

  response = conn.get do |request|
    request.url "/api/v2.0/Me/Messages?$search=%22from:#{prospect_email}%22&$top=20"
    request.headers['Authorization'] = "Bearer #{token['token']}"
    request.headers['Accept'] = 'application/json'
    request.headers['X-AnchorMailbox'] = user_email
  end

  # Okay, this is great: MS tells us to JSON parse what they return, but whether or not they return valid JSON depends on the state of the
  # data that you request, so we'll force it by wrapping it in '[]'.
  parsed_response = JSON.parse("[#{response.body}]")

  if parsed_response[0]["value"].blank?
    # Returns an empty array because we're combining this method and #get_emails in API::ActivitiesController
    return []
  else
    messages = parsed_response[0]["value"]
  end
end

为什么MS会回来MailboxInfoStale

4

3 回答 3

1

更改 X-AnchorMailbox 标头对我有用。

于 2017-08-18T10:37:23.413 回答
0

X-AnchorMailbox 必须设置为连接到您的凭据的电子邮件地址,例如 OAuth 访问令牌。如果它们不同,您将收到此错误。当然可以通过去掉邮件头来解决,但是可能会导致误访问错误的邮箱(比如你有多个邮箱)。

于 2018-01-03T07:24:26.570 回答
0

我有类似的问题并删除了 X-AnchorMailbox 标头(对我来说填充了错误的值)来修复它。

于 2017-02-13T09:07:07.487 回答