繁体   English   中英

Autodesk-forge与auth的问题

[英]autodesk-forge problems with auth

如何用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产品有什么问题。

谢谢

对于记录,从问题的讨论,这里是一个PHP样本的视图和数据可用于此博客文章

<?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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM