BIM 360 API-Forge应用程序-getUsers返回“此帐户不存在”

时间:2020-03-04 17:27:14

标签: python autodesk forge

这里是RESTful API的新手,所以这可能是一个愚蠢的问题:我正在尝试通过以下链接查询BIM 360帐户中的所有用户: https://forge.autodesk.com/en/docs/bim360/v1/reference/http/users-GET/

https://github.com/Autodesk-Forge/design.automation-python-tutorial

我正在使用xiaodongliang的上述存储库作为起点,但是我不断收到以下错误:

Get Users Failed! status = 404 ; message = {"code":1004,"message":"this account doesn't exist."}

这是我所做的更改的列表:

  1. config.py
  2. 中更改了我的BIM 360 / Forge帐户的相关信息
  3. forge_da.py 中为getUsers()添加了一个模块
  4. 相应地修改了getToken(),以便'scope':'account:read'

我检查了每个ID,令牌和机密是否正确,并且已向BIM 360帐户添加了自定义集成。不知道我在这里想念的是什么。请参阅下面添加和更改的模块:

def getToken():
"""Obtain Forge token given a client id & secret"""
req = { 'client_id' : Forge_CLIENT_ID, 'client_secret': Forge_CLIENT_SECRET, 'grant_type' : 'client_credentials','scope':'account:read'}
resp = requests.post(Forge_BASE_URL+'/authentication/v1/authenticate', req)
if resp.status_code == 200:
    config.token = resp.json()['access_token']
    return config.token
else:
    print('Get Token Failed! status = {0} ; message = {1}'.format(resp.status_code,resp.text) )
    return None

def getUsers():
"""Query all BIM 360 Users in given Account"""
print(Forge_ACCOUNT_ID, config.token)
resp = requests.get(Forge_BASE_URL+'/hq/v1/accounts/:account_id/users', headers = {'Authorization': 'Bearer '+ config.token}, json={'account_id' : Forge_ACCOUNT_ID})
if resp.status_code == 200:
    config.users = resp.json()
    return config.users
else:
    print('Get Users Failed! status = {0} ; message = {1}'.format(resp.status_code,resp.text) )
    return None

任何帮助将不胜感激。提前致谢! 约瑟夫·弗伦德

1 个答案:

答案 0 :(得分:0)

哇,我发现了我的错误。我更改了以下行:

resp = requests.get(Forge_BASE_URL+'/hq/v1/accounts/:account_id/users', headers = {'Authorization': 'Bearer '+ config.token}, json={'account_id' : Forge_ACCOUNT_ID})

收件人:

resp = requests.get(Forge_BASE_URL+'/hq/v1/accounts/' + Forge_ACCOUNT_ID + '/users', headers = {'Authorization': 'Bearer '+ config.token})

发布问题迫使我去实际研究它。感谢您的帮助!