获取com.xero.api.XeroApiException:尝试创建/更新发票时发生未授权的错误

时间:2020-05-18 09:04:00

标签: java oauth-2.0 xero-api

我正在使用Xero-Java,并且正在尝试将发票推送到Xero。我在Ouath2授权中要求的范围是:

openid
email
profile
offline_access
accounting.settings
accounting.transactions
accounting.contacts
accounting.journals.read
accounting.reports.read
accounting.attachments

调用AccountingApi.updateInvoice()方法将引发错误:

com.xero.api.XeroApiException: Unauthorized - check your scopes and confirm access to this resource

我的印象是,范围account.transactions可以将发票推送到Xero。我的问题在哪里,如何解决? 谢谢。

1 个答案:

答案 0 :(得分:3)

查看一些日志,看来您的访问令牌已过期。访问令牌只能使用30分钟。

您已经使用offline_access,可以通过使用用户授权过程中提供的刷新令牌(针对SDK github自述文件的自述文件概述)中的刷新请求来获取同一用户的新访问令牌。

您可能需要在每次调用Xero API之前检查令牌到期。