autodesk/forge-client

v1.0.3 2018-06-06 02:35 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:19:50 UTC


README

Forge API: oAuth2 Data-Management OSS Model-Derivative

概述

PHP SDK 允许您轻松地将 Forge REST API 集成到您的应用程序中,包括 OAuth数据管理模型导出设计自动化

要求

安装

Composer

要通过 Composer 安装绑定,请运行

composer require autodesk/forge-client

手动安装

下载文件并包含 autoload.php

require_once('/path/to/ForgeClient/autoload.php');

教程

按照此教程查看逐步认证指南和 Forge API 使用示例。

创建应用

在 Forge 开发者门户上创建一个应用。注意客户端 ID 和客户端密钥。

认证

此 SDK 包含一个 OAuth 2.0 客户端,允许您检索双端和三端令牌。它还允许您刷新三端令牌。教程使用双端和三端令牌调用不同的数据管理端点。

双端令牌

此类型的令牌直接提供给应用程序。

要获取双端令牌,请运行以下代码。请注意,您需要将 your-client-idyour-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-idyour-client-secretyour-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'。

缩略图

thumbnail

支持

forge.help@autodesk.com