import os
import requests
import base64
from xero.auth import OAuth2Credentials
from xero import Xero
from xero.constants import XeroScopes
my_scope = [XeroScopes.OFFLINE_ACCESS, XeroScopes.ACCOUNTING_CONTACTS, XeroScopes.ACCOUNTING_SETTINGS, XeroScopes.ACCOUNTING_TRANSACTIONS_READ,
XeroScopes.ACCOUNTING_TRANSACTIONS, XeroScopes.ACCOUNTING_CONTACTS_READ, XeroScopes.ACCOUNTING_SETTINGS_READ, ]
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
REFRESH_TOKEN_PATH = os.path.join(CURRENT_PATH, "config", "refresh_token2.txt")
CLIENT_ID = 'xxxxx'
CLIENT_SECRET = 'xxxxxx'
CALLBACK_URI = 'https://xero.com/'
TENANT_ID = 'xxxxx'
credentials = OAuth2Credentials(CLIENT_ID, CLIENT_SECRET, token=TOKEN,
callback_uri=CALLBACK_URI, tenant_id=TENANT_ID, scope=my_scope)
XERO = Xero(credentials)
invoices = XERO.invoices.all()
print invoices
accounts = XERO.accounts.all()
print accounts
从xero或xero中的get_attachment_data获取所有帐户时,都会面临oauth_problem错误,每次都使用新令牌。