Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autodesk forge Autodek锻造教程_Autodesk Forge - Fatal编程技术网

Autodesk forge Autodek锻造教程

Autodesk forge Autodek锻造教程,autodesk-forge,Autodesk Forge,我一直在学习Autodesk Forge示例应用程序教程 当我点击按钮连接我的帐户时,我得到了这个错误 {"developerMessage":"The required parameter(s) redirect_uri not present in the request","errorCode":"AUTH-008","more info":"https://forge.autod

我一直在学习Autodesk Forge示例应用程序教程

当我点击按钮连接我的帐户时,我得到了这个错误

{"developerMessage":"The required parameter(s) redirect_uri not present in the request","errorCode":"AUTH-008","more info":"https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/"}

如果您遇到这个错误,您可能会尝试一个3条腿的oauth流。这意味着您没有在请求中提供回调url。既然你没有说你一直在使用哪个教程,让我给你指出两个来源——Forge文档教程或Learn Forge教程

在这两种情况下,在上的应用程序页面中定义回调url都很重要-如果您使用的是本地计算机,那么它应该是http://localhost:3000/mycallback. learnforge材质告诉您将其定义为(请参见):

文档教程中提到要使用的位置

http://sampleapp.com/oauth/callback
但是这里他们假设你拥有域sampleapp.com,这可能不是真的。在本地计算机上开发Web服务器时,需要用自己的域或localhost:port替换sampleapp.com。请注意,在服务器上运行代码时,使用true domain vs localhost,并更新应用程序页面和代码以使用相同的定义,这一点很重要。我通常设置3个应用程序(dev:with localhost:3001、staging:with myapp-staging.autod3sk.net和production:with myapp.autod3sk.net)——这是为了避免必须一直编辑密钥,并使应用程序部署更容易

现在应用程序已经安装好,您需要在请求中使用Oauth API中记录的URL。但是所有参数都应该是URL编码的,否则/字符将被服务器误解。未能在请求中传递正确且编码的URL参数将导致您看到的错误

以下是一个例子:

https://developer.api.autodesk.com/authentication/v1/authorize \
 ?response_type=code \
 &client_id=MYCLIENT_ID \
 &redirect_uri=MY_ENCODE_CALLBACKURL \
 &scope=REQUIRED_SCOPES
替换占位符后,它应该如下所示

https://developer.api.autodesk.com/authentication/v1/authorize\
?response_type=code\
&client_id=oz9f...k2d\
&redirect_uri=http%3a%2f%2flocalhost%3a3000%2fapi%2fforge%2fcallback%2foauth\
&scope=data%3aread
将其复制到浏览器中,在登录和“同意”页面后,服务应返回到浏览器,URL如下:

http://localhost:3000/api/forge/callback/oauth?code=wroM1vFA4E-Aj241-quh_LVjm7UldawnNgYEHQ8I
因为,我们还没有服务器,浏览器会出错,但您可以清楚地看到返回给您的URL以及代码。您知道需要将该代码复制到另一个请求中才能获得最终令牌。这里,我们将使用curl,但理想情况下,请求和回调都应该由服务器代码处理

curl 'https://developer.api.autodesk.com/authentication/v1/gettoken' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id=oz9f...k2d' \
  -d 'client_secret=eUr...Q1e' \
  -d 'grant_type=authorization_code' \
  -d 'code=wroM1vFA4E-Aj241-quh_LVjm7UldawnNgYEHQ8I' \
  -d 'redirect_uri=http://localhost:3000/api/forge/callback/oauth'
理想情况下,所有这些都需要在服务器代码中完成,就像learnforge教程教您做的那样

curl 'https://developer.api.autodesk.com/authentication/v1/gettoken' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'client_id=oz9f...k2d' \
  -d 'client_secret=eUr...Q1e' \
  -d 'grant_type=authorization_code' \
  -d 'code=wroM1vFA4E-Aj241-quh_LVjm7UldawnNgYEHQ8I' \
  -d 'redirect_uri=http://localhost:3000/api/forge/callback/oauth'