调用Autodesk Forge的DerivativeApi出现403错误

403 error in calling DerivativeApi of Autodesk Forge

Autodesk ForgeDerivativeApi 无法使用我的客户端 ID 和密码。 APIs returns 未授权错误,{ statusCode: 403, statusMessage: 'Unauthorized' }.

但他们与示例的客户端 id/secret(来自 https://github.com/Autodesk-Forge/forge-api-nodejs-client/blob/master/samples/dmSample.js)合作。

免费账号调用DerivativeApi(翻译)有限制吗?或者我应该做些什么?

这是示例代码...

var ForgeSDK = require('forge-apis');

// TODO - insert your CLIENT_ID and CLIENT_SECRET
// Below id/secret from the sample are working, but mine is not.
 var CLIENT_ID = 'wmizntnpzCJxPGF9lxsIiTZGbGO2cJqw',
   CLIENT_SECRET = 'g5IPJwvhOHcrdbFy';

var derivativesApi = new ForgeSDK.DerivativesApi();

// Initialize the 2-legged oauth2 client
var oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(CLIENT_ID, CLIENT_SECRET,
  ['data:write', 'data:read', 'bucket:read', 'bucket:update', 'bucket:create'], true);

function defaultHandleError(err) {
  console.error('\x1b[31m Error:', err, '\x1b[0m');
}

oAuth2TwoLegged.authenticate().then(function (credentials) {
  console.log("**** Got Credentials", credentials);
  derivativesApi.getFormats({}, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials()).then(res => {
    console.log(res);
  }, defaultHandleError);
}, defaultHandleError);

谢谢

首先,也是极其重要的一点,切勿 分享您的 ID 和秘密。如果以上是正确的,请创建一个新的 secret(使它无效)。

现在 ID 和秘密应该适用于任何样本,只需确保您为它激活了 API。在您的应用程序上,select Model Derivative API 在屏幕上,如果不可用,please review this article.

最后,上面的代码示例实际上并没有调用模型导数。如果是这样,请注意上传到一个帐户的文件无法从其他帐户访问,并且 URN 是唯一的。