Xero 已将其 API 更改为需要 OAuth2 连接而不是 OAuth1。
我在 OAuth1 中有一个可行的解决方案,但 Oauth2 的示例充其量是稀缺的,但主要用于网站。
我是另一位设法创建 Oauth1 解决方案的开发人员,该解决方案成功地用作机器对机器的解决方案,不涉及 Web 服务器。
Xero 有一些在 Postman 中运行的示例,可以在我的测试环境中轻松运行。
我正在尝试重现 Python3 中刷新令牌的邮递员操作。
我下面的基本代码是我目前所在的位置:
#client_id = "xxxxx"
#client_secret = "xxxxx"
callback_url = "https://api.xero.com/connections"
re_directURI = "https://developer.xero.com"
scopes = "offline_access accounting.contacts accounting.transactions"
refresh_url = "https://identity.xero.com/connect/token"
access_token = open('AccessToken.txt').read()
old_refresh_token = open('RefreshToken.txt','r').read()
# Refresh Token code...
import requests
#def refresh_xero_token(refresh_token):
headers = {
'grant_type': 'refresh_token',
'Content-Type': 'application/json',
}
data = {
'grant_type': 'refresh_token',
'refresh_token': old_refresh_token,
'client_id': client_id,
'client_secret': client_secret
}
print(data,headers)
response = requests.post(refresh_url, headers=headers, data=data)
#return response.json()
print(response.text)
到目前为止,我还没有找到一个在没有 Web 服务器的情况下工作的示例,只是使用 python 与 Xero 服务器通信以将本地数据传输到零 API。
使用 xoauth,.exe (windows) 获取 access_token,然后在邮递员中我可以运行示例以刷新令牌、连接、发票等到演示公司。
而且我相信能够复制这些示例将为我提供获得有效解决方案所需的东西。
目前使用这个 python 代码我只得到 {"error":"invalid_request"}
所以,很明显我错过了一些东西。
我将自己归类为 Python 或 Oauth2 的新手,但由于我之前使用 Oauth1 连接的解决方案取得了成功,我选择了这条路。
我会问 Xero 开发者社区,但我写这篇文章是为了让我们软件的用户将数据推送到他们的 Xero 帐户中,所以为了测试,我只有一个试用帐户,这不能让我访问 Xero 开发者社区.
这本身就很烦人。
Xero支持似乎也没什么用,我试过了。
如果有任何人能够提供帮助,那将是非常棒的。
预先感谢您提供的任何帮助。