在不使用三腿式令牌的情况下,在Autodesk集成中搜索文件夹的解决方案是使用二腿式令牌进行身份验证。
以下是一个Python代码示例,它使用二腿式令牌来搜索Autodesk中的文件夹:
import requests
import json
# Variables
base_url = "https://developer.api.autodesk.com"
client_id = ""
client_secret = ""
folder_id = ""
access_token = ""
# Get 2-legged access token
def get_access_token():
url = base_url + "/authentication/v1/authenticate"
scope = "data:read data:write data:create data:search bucket:create bucket:read account:read account:write"
payload = {
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "client_credentials",
"scope": scope
}
response = requests.post(url, data=payload)
return json.loads(response.text)["access_token"]
# Search folders
def search_folders():
headers = {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/vnd.api+json"
}
url = base_url + "/data/v1/projects/{}/search".format(folder_id)
payload = {
"jsonapi": {
"version": "1.0"
},
"filter": {
"type": "folder",
"attributes": {
"name": "myFolder"
}
}
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
return json.loads(response.text)
access_token = get_access_token()
search_result = search_folders()
print(search_result)
上一篇:Autodesk或任何其他API将DWG转换为JSON。
下一篇:AutodeskInventor2024InventorDesignAutomation-FailedEnvironmentSetup