我正在尝试获取我的旧水桶,但一直给我 400 错误

问题描述 投票:0回答:1

我正在尝试找到一个用于上传一些 Revit 文件的存储桶,以便我可以下载它们。 我知道这些文件就在那里,因为我可以在查看器中看到它们。

我正在使用我的凭据,获取我的 access_token。 但是当我创建如下所示的请求时

bucket_url = 'https://developer.api.autodesk.com/oss/v2/buckets'
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'text/json'
    }

    bucket_response = requests.post(bucket_url, headers=headers)

我收到消息: bucketss_list_response {'reason': '无法解析 JSON'}

我做错了什么?! 这就是我获取 access_token 的方式:

auth_data = {
        'grant_type': 'client_credentials',
        'scope': 'data:read data:write bucket:create bucket:read'
    }
    newBasicAuth = FORGE_CLIENT_ID+":"+FORGE_CLIENT_SECRET
    encoded = base64.b64encode(newBasicAuth.encode())
    headers = {"Content-Type": "application/x-www-form-urlencoded"}
    headers["Authorization"]="Basic " + encoded.decode("utf-8")

    auth_response = requests.post(auth_url, data=auth_data, headers=headers)
    access_token = auth_response.json().get('access_token')

我尝试过:

curl -X GET "https://developer.api.autodesk.com/oss/v2/buckets/YOUR_BUCKET_KEY/objects" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

并且期待:

{
  "items": [
    {
      "objectKey": "model_1.rvt",
      "size": 1234567,
      "contentType": "application/octet-stream"
    },
    {
      "objectKey": "model_2.rvt",
      "size": 2345678,
      "contentType": "application/octet-stream"
    }
  ]
}
autodesk-forge autodesk autodesk-data-management autodesk-data-exchange
1个回答
0
投票

以下是创建和获取桶的过程

第1步.使用下面的curl代码获取2legged令牌

curl --location 'https://developer.api.autodesk.com/authentication/v2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=' \
--data-urlencode 'client_secret=' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=account:read account:write data:read data:write bucket:read bucket:create'

第2步.创建存储桶

curl --location 'https://developer.api.autodesk.com/oss/v2/buckets' \
--header 'Content-Type: application/json' \
--header 'x-ads-region: US' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IlhrUFpfoXzlTYzNZS01oRERBZFBWeFowOF9SUzI1NiIsInBpLmF0bSI6ImFzc2MifQ' \
--data '
  {
    "bucketKey":"testbucket",
    "policyKey":"persistent"
  }
  '

第3步.获取水桶

curl --location 'https://developer.api.autodesk.com/oss/v2/buckets?region=US&limit=100&startAt=1' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IlhrUFpfoXzlTYzNZS01oRERBZFBWeFowOF9SUzI1NiIsInBpLmF0bSI6ImFzc2MifQ'
© www.soinside.com 2019 - 2024. All rights reserved.