Autodesk Forge API技术咨询:如何获取账户ID与账户名称列表?
获取账户ID与账户名称列表的解决方案
Got it, let's walk through how to grab both account IDs and their corresponding names—you're already halfway there with the Hubs endpoint!
核心逻辑:Hub与Account的对应关系
Every Hub in Autodesk Construction Cloud (or BIM 360) is directly tied to an Account. The /project/v1/hubs endpoint actually returns everything you need—you just need to parse the right fields from the response.
具体步骤
- 调用Hubs端点:你已经知道要使用
GET /project/v1/hubs接口,记得带上拥有data:read权限的有效访问令牌。 - 提取账户名称:在返回的响应中,每个
hub对象的attributes.name字段就是对应的账户名称。 - 提取账户ID:Hub ID的格式固定为
b.<account_id>,只需去掉前缀b.,就能得到原始的账户ID。
示例响应解析
下面是响应片段,标注了关键字段:
{ "data": [ { "type": "hubs", "id": "b.123e4567-e89b-12d3-a456-426614174000", "attributes": { "name": "Acme Construction Co.", "region": "EMEA" } } ] }
- 账户ID:
123e4567-e89b-12d3-a456-426614174000(将Hub ID按.分割,取第二部分) - 账户名称:
Acme Construction Co.(直接取自attributes.name)
快速代码示例(Python)
如果用Python处理,可以参考这段代码来解析响应:
import requests access_token = "YOUR_ACCESS_TOKEN" url = "https://developer.api.autodesk.com/project/v1/hubs" headers = {"Authorization": f"Bearer {access_token}"} response = requests.get(url, headers=headers) hubs = response.json()["data"] account_list = [] for hub in hubs: account_id = hub["id"].split(".")[1] account_name = hub["attributes"]["name"] account_list.append({"account_id": account_id, "account_name": account_name}) print(account_list)
搞定!不需要额外调用其他接口,你需要的所有数据都在Hubs接口的响应里了。
内容的提问来源于stack exchange,提问作者Mabana
相关产品推荐
相关产品推荐

