【问题标题】:autodesk-forge problems with authAutodesk-forge 身份验证问题
【发布时间】:2016-12-08 00:40:03
【问题描述】:

如何解决client_id的问题??

我写这个 $node 节点 AuthTokenServer.js

然后去浏览器写下答案,“localhost:5000/” 是I'm alive!

然后我测试,“localhost:5000/auth”,答案是......

AuthTokenServer: getting PRODUCTION token...
{ "developerMessage":"The client_id specified does not have access to the api product","userMessage":"","errorCode":"AUTH-001","more info":"......}

嗯,我搜索了几个帖子,但我没有找到任何东西。

谁能帮帮我?

我看到 Autodesk API 的典型错误

http://autodesk-test.apigee.net/documentation/v1/errors/errors.html

但我不知道我的 API 产品有什么问题。

谢谢

【问题讨论】:

  • 当您在门户网站上创建新应用程序时,您可以选择生成的密钥也可以让您访问哪些 API。你也许可以放一个 sn-p 来显示你在 AuthTokenServer.js 中运行的代码......
  • 确实如此。我添加了所有可用的 API,但效果不佳。我现在已经激活了 3D Print API、Data Management API、BIM 360 API、Design Automatio API 和 Model Derivate API。另一方面,我有两个应用程序,并且有时会重新生成它。
  • “我还活着”响应是标准的 PHP 页面,这是预期的。关于错误,我们需要更多信息,例如您调用的 Forge 端点。你能添加那段代码吗?这是一个快速的 v1 示例adndevblog.typepad.com/cloud_and_mobile/2016/01/…
  • 嗯,Forge 端点如下:127.0.0.1:5000/auth 我在浏览器中写它,就像这个 github 的步骤 9); github.com/GetSomeRest/AuthTokenServer_Simple 答案是 { "developerMessage":"指定的 client_id 无权访问 api 产品","userMessage":"","errorCode":"AUTH-001","more info":"@ 987654325@"}
  • 我用 localhost:5000/auth-stg 和 localhost:5000/auth-dev 等其他端点进行测试,但响应相同。

标签: authentication autodesk-forge


【解决方案1】:

为了记录,从关于问题的讨论中,这里是一个用于查看和数据的 PHP 示例,可在 this blog post 获得。

<?php
// we need a REST Library, found HttpFul
// Download from http://phphttpclient.com/
// You may need to add permissions for MAC OS with Apache
//     sudo chmod -R 755 /library/webserver/documents
//     (assuming default folder)
include 'httpful.phar';

// define some constants for this quick sample
define(CONSUMER_KEY, "your key");
define(CONSUMER_SECRET, "your secret");
define(BASE_URL, 'https://developer.api.autodesk.com');

// if the request URL contains the method being requested
// for instance, a call to view.and.data.php/authenticate
// will redirect to the function with the same name
$apiName = explode('/', trim($_SERVER['PATH_INFO'],'/'))[0];
if (!empty($apiName)){
    // get the function by API name
    try{ $apiFunction = new ReflectionFunction($apiName);}
    catch (Exception $e) { echo ('API not found');}

    // run the function and 'echo' it's reponse
    if ($apiFunction != null) echo $apiFunction->invoke();

    exit(); // no HTML output
}

// now the APIs
function authenticate(){
    // request body (client key & secret)
    $body = sprintf('client_id=%s' . 
                    '&client_secret=%s' . 
                    '&grant_type=client_credentials',
                    CONSUMER_KEY, CONSUMER_SECRET);

    // prepare a POST request following the documentation
    $response = 
        \Httpful\Request::post(
          BASE_URL . '/authentication/v1/authenticate')
        ->addHeader('Content-Type', 'application/x-www-form-urlencoded')
        ->body($body)
        ->send(); // make the request

    if ( $response->code == 200)
        // access the JSON response directly
        return $response->body->access_token; 
    else
        // something went wrong...
        throw new Exception('Cannot authenticate');
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Minimum PHP View and Data Sample</title>
    <link type="text/css" rel="stylesheet" href="https://developer.api.autodesk.com/viewingservice/v1/viewers/style.css" />
</head>
<script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js?v=1.2.23"></script>
<script>
// This is the basic JavaScript sample code available at the documentation
// It's optimized for 3D models and slightly adjusted for this case

// Show the model specified on the URN parameter
function showModel() {
    var options = {
        'document': 'urn:' + document.getElementById('modelURN').value,
        'env': 'AutodeskProduction',
        'getAccessToken': getToken,
        'refreshToken': getToken,
    };
    var viewerElement = document.getElementById('viewer');
    var viewer = new Autodesk.Viewing.Viewer3D(viewerElement, {});
    Autodesk.Viewing.Initializer(
        options,
        function () {
            viewer.initialize();
            loadDocument(viewer, options.document);
        }
    );
}

// Load the document (urn) on the view object
function loadDocument(viewer, documentId) {
    // Find the first 3d geometry and load that.
    Autodesk.Viewing.Document.load(
        documentId,
        function (doc) { // onLoadCallback
            var geometryItems = [];
            geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {
                'type': 'geometry',
                'role': '3d'
            }, true);
            if (geometryItems.length > 0) {
                viewer.load(doc.getViewablePath(geometryItems[0]));
            }
        },
        function (errorMsg) { // onErrorCallback
            alert("Load Error: " + errorMsg);
        }
    );
}

// This calls are required if the models stays open for a long time and the token expires
function getToken() {
    return makePOSTSyncRequest("view.and.data.php/authenticate");
}

function makePOSTSyncRequest(url) {
    var xmlHttp = null;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST", url, false);
    xmlHttp.send(null);
    return xmlHttp.responseText;
}
</script>
<body>
    <div>This is a minimum sample in PHP5.
        <br /> First edit this file and enter your consumer key and consumer secret. Request at <a href="http://forge.autodesk.com">Forge portal</a>.
        <br /> To use this sample you need a model URN. Please upload a model at <a href="http://models.autodesk.io">Models.Autodesk.IO</a></div>
    <hr />
    <div>
        Specify a model URN:
        <input type="text" id="modelURN" />
        <input type="button" value="View model" onclick="showModel()">
    </div>
    <hr />
    <div id="viewer">
    </div>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2019-06-15
    • 2019-12-27
    • 2021-06-03
    • 2018-03-15
    • 2019-11-09
    • 1970-01-01
    • 2022-10-17
    • 2018-01-18
    相关资源
    最近更新 更多