我按照forge教程将forge查看器嵌入到html页面中。我最终进入了这个锻造制造的页面,链接:https://autodesk-forge.github.io/forge-tutorial-postman/display_svf.html我知道如何使用cURL检索访问令牌,但是我想修改该网站,这样我就不必自己输入访问令牌。我想从cURL响应中自动导入访问令牌作为该网站的访问令牌。这怎么可能。网页的代码如下:https://github.com/Autodesk-Forge/forge-tutorial-postman/blob/master/docs/display_svf.html当我点击网页上的提交时,如何添加一个函数/方法来自动检索访问令牌。任何帮助都是非常乐意的!干杯
您要查找的服务器端代码是:
app.get('/api/forge/oauth', function (req, res) {
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
data: querystring.stringify({
client_id: FORGE_CLIENT_ID,
client_secret: FORGE_CLIENT_SECRET,
grant_type: 'client_credentials',
scope: scopes
})
})
.then(function (response) {
// Success
access_token = response.data.access_token;
console.log(response);
res.send('<p>Authentication success!</p>');
})
.catch(function (error) {
// Failed
console.log(error);
res.send('Failed to authenticate');
});
});