Autodesk forge php

Autodesk forge with php

我在 PHP 中使用 autodesk forge 开始了一个项目,但是我遇到了一个我无法解决的错误。我在本网站 https://learnforge.autodesk.io/#/environment/setup/2legged 中做了所有工作,以在 PHP 和 Node.js 中创建服务器。在节点中我获得了成功,但我的朋友们想在 php 中取得成功。 有 2 个错误,我解决了一个: 第一个是:

HP Fatal error:  Uncaught TypeError: Argument 1 passed to Dotenv\Dotenv::create() must be an instance of Dotenv\Repository\RepositoryInterface, string given, called in /Users/.../forgeExample/server/config.php on line 14 and defined in /Users/.../forgeExample/vendor/vlucas/phpdotenv/src/Dotenv.php:83
Stack trace:
#0 /Users/.../forgeExample/server/config.php(14): Dotenv\Dotenv::create('/Users/mackleym...')
#1 /Users/.../forgeExample/server/oauth.php(14): Autodesk\ForgeServices\ForgeConfig::getForgeID()
#2 /Users/.../forgeExample/server/oauth.php(49): Autodesk\ForgeServices\AuthClientTwoLegged->__construct()
#3 /Users/.../forgeExample/index.php(8): include_once('/Users/mackleym...')
#4 {main}
  thrown in /Users/.../forgeExample/vendor/vlucas/phpdotenv/src/Dotenv.php on line 83

我在 vlucas/phpdotenv 的帮助下解决了这个问题,方法是将 server/config.php 中的第 14 行从: $dotenv = Dotenv::create(__DIR);$dotenv = Dotenv::createImmutable(__DIR__);

服务器运行并停止加载示例,出现第二个错误: PHP 致命错误:

Uncaught Autodesk\Core\Exception\RuntimeException: The client_id specified does not have access to the api product in /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/TokenFetcher.php:108
Stack trace:
#0 /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/TokenFetcher.php(87): Autodesk\Auth\TokenFetcher->makeRequest('https://develop...', Array)
#1 /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/OAuth2/AbstractOAuth2.php(143): Autodesk\Auth\TokenFetcher->fetch('https://develop...', 'client_credenti...', Array, Array)
#2 /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/OAuth2/TwoLeggedAuth.php(15): Autodesk\Auth\OAuth2\AbstractOAuth2->fetchAccessToken('authentication/...', 'client_credenti...')
#3 /Users/mackleymagalhaes/development/.../forgeExample/server/oauth.php(38): Autodesk\Auth\OAuth2\TwoLeggedAuth->fetchToken()
#4 /Users/mackleymagalhaes/developme in /Users/mackleymagalhaes/development/.../forgeExample/vendor/klein/klein/src/Klein/Klein.php on line 954
[Thu Sep  3 16:59:07 2020] [::1]:58380 [200]: GET /api/forge/oss/buckets?id=%23 - Uncaught Autodesk\Core\Exception\RuntimeException: The client_id specified does not have access to the api product in /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/TokenFetcher.php:108
Stack trace:
#0 /Users/mackleymagalhaes/development/.../forgeExample/vendor/autodesk/core/lib/Auth/TokenFetcher.php(87): Autodesk\Auth\TokenFetcher->makeRequest('https://develop...', Array)
#1 /Users/.../forgeExample/vendor/autodesk/core/lib/Auth/OAuth2/AbstractOAuth2.php(143): Autodesk\Auth\TokenFetcher->fetch('https://develop...', 'client_credenti...', Array, Array)
#2 /Users/.../forgeExample/vendor/autodesk/core/lib/Auth/OAuth2/TwoLeggedAuth.php(15): Autodesk\Auth\OAuth2\AbstractOAuth2->fetchAccessToken('authentication/...', 'client_credenti...')
#3 /Users/.../forgeExample/server/oauth.php(38): Autodesk\Auth\OAuth2\TwoLeggedAuth->fetchToken()
#4 /Users/mackleymagalhaes/developme in /Users/mackleymagalhaes/development/.../forgeExample/vendor/klein/klein/src/Klein/Klein.php on line 954

有人知道这是什么吗?


将我的 vlucas/phpdoenv 版本降级到 ^3.0.0 后,我在控制台上遇到了这个错误:

[Tue Sep 8 12:12:13 2020] [404] /api/forge/oss/buckets - No such file or directory [Tue Sep 8 09:12:14 2020] PHP Fat al error: Uncaught Autodesk\Forge\Client\ApiException: [403] Error connecting to the API (https://developer.api.autodesk.com/oss/v2/buckets) in ..\forge-example2\vendor\autodesk\forge-client\lib\ApiClient.php:261 S tack trace: #0 ..\forge-example2\vendor\autodes k\forge-client\lib\Api\AbstractApi.php(89): Autodesk\Forge\Client\ApiClient->callApi('/oss/v2/buckets', 'GET', Array, '', Array, '\Autodesk\Forge...', '/oss/v 2/buckets') #1 ..\forge-example2\vendor\autodesk\forge-cl ient\lib\Api\BucketsApi.php(390): Autodesk\Forge\Client\Api\AbstractApi->callApi('/oss/v2/ buckets', 'GET', Array, '', Array, '\Autode sk\Forge...', '/oss/v2/buckets') #2 ..\forge-example2\vendor\autodesk\forge-client\lib\Api \BucketsApi.php(330): Autodesk\Forge\Client\Api\BucketsApi->getBucketsWithH ttpInfo(NULL, NULL, NULL) #3 ..\forge- example2\server\oss.php(47): Autodesk\Forge\Client\Api\BucketsApi->getBuckets() #4 D:\UFU\for ge-example2\index.php(26): Autodesk\ForgeS ervices\DataManagement->getBucketsAndObjects() #5 [internal fun in ..\forge-example2\vendor\klein\klein\src\Klein\Klein.php on line 954

[Tue Sep 8 09:12:14 2020] [::1]:54087 [200]: GET /api/forge/oss/buckets?id=%23 - Uncaught Autodesk\Forge\Client\ApiException: [403 ] Error connecting to the API (https://developer.api.autodesk.com/oss/v2/buckets) in D:\UFU\forge- example2\vendor\autodesk\forge-client\lib\Ap iClient.php:261 Stack trace: #0 ..\forge-example2\vendor\autodesk\forge-client\lib\Api \AbstractApi.php(89): Autodesk\Forge\C lient\ApiClient->callApi('/oss/v2/buckets', 'GET', Array, '', Array, '\Autodesk\Forge...', '/oss/v2/buckets') #1 ..\forge-exam ple2\vendor\autodesk\forge-client\lib\Api\BucketsApi.php(390): Autodesk\Forge\Client\Api\Abst ractApi->callApi('/oss/v2/buckets', 'GET', Array, '', Array, '\Autodesk\Forge...', '/oss/v2/b uckets') #2 ..\forge-example2\vendor\auto desk\forge-client\lib\Api\BucketsApi.php(330): Autodesk\Forge\Client\Api\BucketsApi->getBuc ketsWithHttpInfo(NULL, NULL, NULL) #3 ..\forge-example2\server\oss.php(47): Autodesk\Forge\Client\Api\BucketsApi->getBuckets() #4 ..\forge-example2\index.php(26): Aut odesk\ForgeServices\DataManagement->getBucketsAndObjects() #5 [internal fun in D:\UFU\forge-ex ample2\vendor\klein\klein\src\Klein\Klein.php on line 954

[Tue Sep 8 09:12:14 2020] [::1]:54087 Closing

我 运行 遇到了同样的问题,在我的情况下,它最终是 vlucas/phpdotenv 依赖项的某些版本不匹配。这是我为使 PHP 示例正常工作所做的工作(在项目的根文件夹中,使用 bash):

# confirm you have a good version of PHP (in my case it's 7.3.11)
php -v

# remove composer dependencies
rm -rf vendor
rm composer.lock

# setup composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar install

# create the .env file
cp server/.env.example server/.env
vim server/.env # add your client ID and client secret

# start the app
php -S localhost:3000 -t .

# now, open your browser and go to http://localhost:3000/www/index.html