我在获得Autodesk Forge API以接受我的文件成为一个光示波器时遇到了问题。我从API调用中得到的错误消息是:
{"developerMessage":"Access token provided is invalid or expired.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}这个错误让我感到困惑,因为我刚刚成功地使用了同样的forge_access_token来创建我要添加这些文件的光子示波器。
而“errorCode”:“部分没有给我提供任何关于哪里出了问题的线索。
下面是我的程序中的代码序列:
1.我正在使用以下代码成功地获得一个access_token:
# Request for a 2-legged OAuth access token
json=`curl -s $FORGE_URL/authentication/v1/authenticate \
-d client_id=$CLIENT_ID\
-d client_secret=$CLIENT_SECRET\
-d grant_type=client_credentials\
-d scope=data:read+data:write
`
forge_access_token=`echo $json | jq -r .access_token`
echo "forge_access_token: $forge_access_token"2.然后,我在以下代码中使用返回的forge_access_token成功地请求一个新的光导纤维:
json=`curl -s $FORGE_URL/photo-to-3d/v1/photoscene \
-X 'POST' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $forge_access_token" \
-d "scenename=$scan_id" \
-d 'scenetype=object' \
-d 'format=obj,rcm'
`
# echo $json
photosceneid=`echo $json | jq -r .Photoscene.photosceneid`
echo "Created Photoscene: $photosceneid"3.但是,当我调用这个代码来向这个新的光子示波器添加图像文件时,它没有添加它们:
JPG_FILES=$scan_dir/*.jpg
i=0
for image_file in $JPG_FILES
do
file_name=`basename $image_file`
json=`curl -s $FORGE_URL/photo-to-3d/v1/file \
-H 'Authorization: Bearer $forge_access_token' \
-d 'photosceneid=$photosceneid' \
-d 'type=image' \
-d 'file[$i]=$image_file'
`
i=$((i+1))我的错误消息失败了:
{"developerMessage":"Access token provided is invalid or expired.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}还有其他的Forge捕捉API用户看到过吗?你是怎么解决的?
发布于 2020-06-17 08:54:56
上传所有JPEG文件需要多长时间?访问令牌通常设置为在一小时内过期,因此如果有太多的图像或它们太大,则可能在上传所有内容之前令牌过期。
另外,考虑使用带有curl标志的-v,这样您也可以看到正在发送的确切的请求头,这只是为了确保$forge_access_token内插没有什么奇怪的事情发生。
如果这两个问题都不是上面提到的,请通过forge (dot) help (at) autodesk (dot) com联系我们--尽可能多地了解你的情况--我们会把它传递给工程团队。
发布于 2020-06-18 03:13:59
问题在于BASH如何处理单引号和双引号。如果$variable出现在单引号中,而不是双引号中,那么BASH不能代替它们。
以下重写删除的最后一节“提供的访问令牌无效或过期”。错误:
JPG_FILES=$scan_dir/*.jpg
i=0
for image_file in $JPG_FILES
do
file_name=`basename $image_file`
json=`curl -s $FORGE_URL/photo-to-3d/v1/file \
-H "Authorization: Bearer $forge_access_token" \
-d "photosceneid=$photosceneid" \
-d 'type=image' \
-d "file[$i]=$image_file"
`
i=$((i+1))在通过切换到双引号来修正上面的代码之后,我现在有了一个上传文件的新问题,我将把它作为一个新的问题来发布,因为它与上面的不同。
https://stackoverflow.com/questions/62420585
复制相似问题