我有一个与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
?
答案 0 :(得分:1)
更改X-AnchorMailbox标题对我有用。
答案 1 :(得分:0)
我遇到了类似的问题,并删除了X-AnchorMailbox标题(我填写了错误的值)来修复它。
答案 2 :(得分:0)
必须将X-AnchorMailbox设置为连接到您的凭据的电子邮件地址,例如OAuth访问令牌。他们不同,你会得到这个错误。当然可以通过删除标题来修复它,但它可能导致错误地访问错误的邮箱(例如,如果你有多个邮箱)。