0

我正在使用 Softlayer java 客户端 Lib 开发一个云门户。

我的用户 ID 是一个主帐户,就在品牌下方,并使用 createCustomerAccount() 创建了帐户。创建帐户后,我无法使用 getAllOwnedAccounts() 检索帐户列表。执行以下代码后,只能显示我的帐户。其他账号已经创建成功,可以在“agent.softlayer.com”上找到这些账号。

这是我的代码..

@Test
    public void testConnect() throws Exception {

        ApiClient client = new RestApiClient().withCredentials(userId, apiKey);

        Brand brand = Account.service(client).getBrand();

        List<Account> accountList = Brand.service(client, brand.getId()).getAllOwnedAccounts();

        for (Account account : accountList) {
            System.out.println(account.getCompanyName() + ", state : "+ account.getState());
        }
    }

这是另一个代码..


Brand brand = Account.service(client).getBrand();

Brand.Service brdSrv = Brand.service(client, brand.getId());

brdSrv.withMask().allOwnedAccounts();

Brand brd = brdSrv.getObject();

List<Account> accountList = brd.getAllOwnedAccounts();

此代码也不起作用..

期待您的反馈。谢谢

麦克风

4

1 回答 1

0

试试这个代码是在 Python 中:

import SoftLayer.API

USERNAME = 'set me'
API_KEY = 'set me'

client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)

accountService = client['SoftLayer_Account']
brandService = client['SoftLayer_Brand']

# Getting the brands
brands = accountService.getOwnedBrands()
for brand in brands:
    brandId = brand['id']
    # Getting the owned Accounts
    accounts = brandService.getAllOwnedAccounts(id=brandId)
    for account in accounts:
        print(account['companyName'])

我认为问题在于您没有使用正确的品牌 ID。

于 2016-01-26T13:07:46.207 回答