I am following this guide to try and use AutoDesk's Reality Capture API. The code in the documentation is written in JavaScript but I have written a script in Python.

I am getting an error when creating a PhotoScene. The code supplied by ADS is:

app.get("/api/aps/recap/photoscene/add", function (req, res) {
  Axios({
    method: "POST",
    url: "https://developer.api.autodesk.com/photo-to-3d/v1/photoscene",
    headers: {
      "content-type": "application/json",
      Authorization: "Bearer " + access_token,
    },
    data: querystring.stringify({
      scenename: "myscenename",
      scenetype: "object",
      format: "rcm",
    }),
  })
    .then(function (response) {
      // Success
      console.log(response);
      if (response.data.Error) {
        res.send(response.data.Error.msg);
      }
      var photosceneId = response.data.Photoscene.photosceneid;
      var nextLink =
        "/api/aps/recap/photoscene/upload?photosceneid=" + photosceneId;
      res.send(
        '<p>Photoscene added!</p><a href="' +
          nextLink +
          '">Upload files to photoscene</a>'
      );
    })
    .catch(function (error) {
      // Failed
      console.log(error);
      res.send("Failed to create a photoscene");
    });
});

And this is my function:

def add_photoscene(access_token, scene_name, scene_type, format="obj"):
    url = "https://developer.api.autodesk.com/photo-to-3d/v1/photoscene"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {access_token}"
    }

    data = {
        "scenename": scene_name, 
        "scenetype": scene_type,
        "format": format,
    }

    try:
        response = requests.post(url, headers=headers, json=data) # Note use of json instead of data
        response.raise_for_status()

        photoscene_id = response.json().get('Photoscene', {}).get('photosceneid')
        if photoscene_id:
            return photoscene_id
        else:
            return None
    except requests.RequestException as e:
        print(e)
        return None

However, I get an Unauthorized for url error when trying to call this function as part of my script. I have signed into AutoDesk Developer Platform Services, created a custom App with relevant client ID and client secret and have confirmed that the access token obtained from doing the OAuth is the same one that has been passed into my add_photoscene() function.

If anybody has any idea as to what is going wrong, that would be very helpful! Thank you!

I tried verifying that my access token was the same across the calls. I looked at Autodesk community blog posts but could not find any relevant information. I verified that I have full access during my free Premium trial of all AutoDesk API services.

0

There are 0 best solutions below