oskmoz / forge-client
Requires
- php: >=5.4
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- oskmoz/autodesk-core: ^1.1
- salsify/json-streaming-parser: ^8.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ~1.12
- phpunit/phpunit: ~4.8
- satooshi/php-coveralls: ~1.0
- squizlabs/php_codesniffer: ~2.6
- symfony/var-dumper: ^3.2
This package is auto-updated.
Last update: 2024-09-16 17:19:28 UTC
README
概述
此PHP SDK 允许您轻松将 Forge REST API 集成到您的应用程序中,包括 OAuth、数据管理、模型衍生和设计自动化。
要求
- PHP 版本 5.4.0 或更高。
- 在 Forge 开发者门户 上注册的应用。
开始之前
- 由于分支,文档并不全面
- 从 forge-php-client 分支出来,以修复自 2022 年 9 月 30 日起的弃用问题,并保持此包正常工作
安装
Composer
要使用 Composer 安装绑定,请运行
composer require oskmoz/forge-php-client
手动安装
下载文件并包含 autoload.php
require_once('/path/to/ForgeClient/autoload.php');
教程
遵循此教程查看逐步认证指南,以及如何使用 Forge API 的示例。
创建应用
在 Forge 开发者门户上创建一个应用。注意客户端 ID 和客户端密钥。
认证
此 SDK 包含一个 OAuth 2.0 客户端,允许您检索双因素和三因素令牌。它还允许您刷新三因素令牌。教程使用双因素和三因素令牌调用不同的数据管理端点。
双因素令牌
此类型令牌直接提供给应用程序。
要获取双因素令牌,请运行以下代码。注意,您需要将 your-client-id
和 your-client-secret
替换为您应用的客户端 ID 和客户端密钥。
<?php Autodesk\Auth\Configuration::getDefaultConfiguration() ->setClientId('<your-client-id>') ->setClientSecret('<your-client-secret>'); $twoLeggedAuth = new Autodesk\Auth\OAuth2\TwoLeggedAuth(); $twoLeggedAuth->setScopes(['bucket:read']); $twoLeggedAuth->fetchToken(); $tokenInfo = [ 'applicationToken' => $twoLeggedAuth->getAccessToken(), 'expiry' => time() + $twoLeggedAuth->getExpiresIn(), ];
三因素令牌
生成认证 URL
为了从用户那里获取权限以检索访问令牌,您将用户重定向到授权页面。
将 your-client-id
、your-client-secret
和 your-redirect-url
替换为您应用的客户端 ID、客户端密钥和重定向 URL,并运行代码以创建授权页面 URL。
请注意,重定向 URL 必须与您创建应用时提供的回调 URL 匹配。
<?php Autodesk\Auth\Configuration::getDefaultConfiguration() ->setClientId('<your-client-id>') ->setClientSecret('<your-client-secret>') ->setRedirectUrl('<your-redirect-url>'); $threeLeggedAuth = new Autodesk\Auth\OAuth2\ThreeLeggedAuth(); $threeLeggedAuth->addScope('code:all'); $authUrl = $threeLeggedAuth->createAuthUrl();
检索授权代码
用户在授权页面获得权限后,Forge 将页面重定向到您创建应用时提供的重定向 URL。授权代码将返回在查询字符串中。
GET /callback?code={authorizationCode}
检索访问令牌
使用您收到的授权代码请求访问令牌,如下所示
<?php Autodesk\Auth\Configuration::getDefaultConfiguration() ->setClientId('<your-client-id>') ->setClientSecret('<your-client-secret>') ->setRedirectUrl('<your-redirect-url>'); $threeLeggedAuth = new Autodesk\Auth\OAuth2\ThreeLeggedAuth(); $threeLeggedAuth->addScope('code:all'); $threeLeggedAuth->fetchToken($_GET['code']); $userToken = [ 'accessToken' => $threeLeggedAuth->getAccessToken(), 'refreshToken' => $threeLeggedAuth->getRefreshToken(), 'expiry' => time() + $threeLeggedAuth->getExpiresIn(), ];
请注意,访问令牌在短时间内会过期。expires_in
字段表示访问令牌的有效期为多少秒。要刷新访问令牌,请调用 $threeLeggedAuth->refreshToken($refreshToken);
方法。
API 调用示例
使用 TwoLeggedAuth
对象或 ThreeLeggedAuth
对象调用 Forge API。
<?php $apiInstance = new Autodesk\Forge\Client\Api\ActivitiesApi($threeLeggedAuth); $activity = new \Autodesk\Forge\Client\Model\Activity(); // \Autodesk\Forge\Client\Model\Activity $result = $apiInstance->createActivity($activity);
API 文档
您可以在 开发者门户 上获取 API 的完整文档。
API 端点文档
所有 URI 都相对于 https://developer.api.autodesk.com。例如,createActivity URI 是 'https://developer.api.autodesk.com/autocad.io/us-east/v2/Activities'。
缩略图
支持
ISIBIM
库的新版本