在 BIM 360 API 中,当我们从文件夹中删除文件夹时,Get folder 调用仍会返回 OK,这可能会导致一些问题。此问题的解决方法是使用实际的文件夹 ID 来获取文件夹信息,并在文件夹已被删除时处理错误。
以下是一个示例代码,演示如何获取文件夹信息并处理错误:
import requests
# Replace {folderId} with actual folder ID
folder_id = "{folderId}"
url = f"https://developer.api.autodesk.com/data/v1/projects/b.{project_id}/folders/{folder_id}"
# Set up headers with access token
headers = {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/vnd.api+json"
}
# Make GET request to BIM360 API
response = requests.get(url, headers=headers)
# Check response status code
if response.status_code == 200:
# Folder information is returned, handle data as usual
folder_data = response.json()
folder_name = folder_data["data"]["attributes"]["name"]
print(f"Folder name: {folder_name}")
else:
# Folder can no longer be accessed, handle error as desired
print("Error accessing folder information")
在这个示例中,我们使用变量 folder_id
来存储实际的文件夹 ID,并在 URL 中使用它来获取文件夹信息。如果 API 调用返回 200 状态码,则文件夹信息被返回,并可以按照通常的方式处理。如果 API 调用返回任何其他状态码,则文件夹已被删除,我们可以处理错误并采取必要的措施。
请注意,此代码示例没有包含获取访问令牌的代码。您需要使用适当的 OAuth2 认证流程来获取访问令牌,然后将其包含在 headers
中,作为 API 调用的一部分。