Im starting a project with autodesk forge in PHP, but I got an arror that I cant solve. I did everything in this site https://learnforge.autodesk.io/#/environment/setup/2legged to create a server in PHP and Node.js. In node I got success but my friends want to make it in php. Got 2 errors and I solve one: The first one was:
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
I solve this with the help in vlucas/phpdotenv
by changing the line 14 in server/config.php
from:
$dotenv = Dotenv::create(__DIR);
to $dotenv = Dotenv::createImmutable(__DIR__);
The server runs and stops loading the exemple with this second error: PHP Fatal error:
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
anyone know what is this?
after downgrade my version of vlucas/phpdoenv to ^3.0.0 I`ve got this errors on console:
[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
I ran into the same issue, and in my case it ended up being some version mismatch of the vlucas/phpdotenv
dependency. Here's what I did to get the PHP sample working (in the project's root folder, using 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