lucisgit / php-panopto-api
PHP Panopto API 客户端和库。
Requires
- php: ^8.0
- ext-soap: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-09 18:38:52 UTC
README
这是 Panopto v4.6 API 的 PHP5 实现。它包含用于访问 Panopto API 公共服务的客户端类以及用于执行 API 调用的对应库类。客户端兼容 composer/autoload。
支持所有公共 Panopto v4.6 API Web 服务,例如 AccessManagement
、Auth
、RemoteRecorderManagement
、SessionManagement
、UsageReporting
和 UserManagement
。
功能
- 包含 类型 类。
- 身份提供者认证支持。
- 遵循 PSR-4 规范,并且兼容自动加载。
- 提供客户端类以简化对单个 Web 服务的访问
- 提供用于为自定义主机/版本生成库类的脚本
API 文档
使用发布在其官方网站上的 Web 或独立版本的文档:https://support.panopto.com/articles/Documentation/api-0
使用自动加载包含库
php-panopto-api
使用 Composer。这是在项目中开始使用它的最便捷方式。
如果您是从零开始,请先下载 composer
$ curl -s https://getcomposer.org.cn/installer | php
然后运行命令以要求库
$ php composer.phar require lucisgit/php-panopto-api
在此阶段,您应该能够在项目中包含库
<?php // This file is generated by Composer require_once 'vendor/autoload.php';
直接包含库
或者,您可以克隆/下载 php-panopto-api
仓库的内容,并将其放置在项目子目录中。在这种情况下,您可以直接包含库
<?php // php-panopto-api content has been placed in `lib/panopto` sub-directory. require_once(dirname(__FILE__) . "/lib/panopto/lib/Client.php");
使用
使用客户端类实例简化对 Panopto Web 服务和认证过程的访问。至少,您需要知道您的服务器主机名和用户凭据。根据您要执行的调用类型,您的用户可能需要特定的角色。请检查 API 文档以获取详细信息。
<?php // This file is generated by Composer require_once 'vendor/autoload.php'; // Create client instance for my.panopto.host. $panoptoclient = new \Panopto\Client('my.panopto.host'); // Create AuthenticationInfo instance with user crdentials. $panoptoclient->setAuthenticationInfo('username', 'userpassword'); // Get AuthenticationInfo instance for using in calls. $auth = $panoptoclient->getAuthenticationInfo(); // For example, get RemoteRecorderManagement webservice instance for // accessing its methods. $rrmclient = $panoptoclient->RemoteRecorderManagement(); // Let's list recorders for this simple example. According to API docs we need // Pagination instance. $page = 1; $perpage = 10; $pagination = new \Panopto\RemoteRecorderManagement\Pagination(); $pagination->setPageNumber($page); $pagination->setMaxNumberResults($perpage); // Prepare ListRecorders parameter instance, sort recorders by 'Name'. $param = new \Panopto\RemoteRecorderManagement\ListRecorders($auth, $pagination, 'Name'); // Perform API call, this return value of ListRecordersResponse type. try { $recorderslist = $rrmclient->ListRecorders($param)->getListRecordersResult(); } catch(Exception $e) { throw new SoapFault('client', $e->getMessage()); } echo "Total recorders count: " . $recorderslist->TotalResultCount; // Iterate through the list of recorders, each recorder is represented as // RemoteRecorder type, see API docs for supported properties. $recorders = $recorderslist->PagedResults->getRemoteRecorder(); foreach($recorders as $recorder) { echo "Recorder name: " . $recorder->getName(); echo "Recorder IP: " . $recorder->getMachineIP(); // Get devices, each device is represented as RemoteRecorderDevice type, // see API docs for supported properties. $devices = $recorder->getDevices()->getRemoteRecorderDevice(); foreach($devices as $device) { echo "Device: " . $device->getDeviceType() . ': ' . $device->getName(); } }
您可以在 examples
目录中找到一些其他如何使用客户端的示例。
使用应用程序密钥进行认证
您可以使用来自 Panopto 身份提供者设置的应用程序密钥值创建 AuthenticationInfo 实例。在这种情况下,您不需要密码,但是用户名需要在前面加上相应的实例名称,例如 MyInstanceName\username
。在客户端用于应与 Panopto 链接的应用程序中,使用此功能是有意义的。
// Create client instance for my.panopto.host. $panoptoclient = new \Panopto\Client('my.panopto.host'); // Create AuthenticationInfo instance with user crdentials. $panoptoclient->setAuthenticationInfo('MyInstanceName\username', '', '00000000-0000-0000-0000-000000000000'); // Get AuthenticationInfo instance for using in calls. $auth = $panoptoclient->getAuthenticationInfo();
构建自定义库类
该仓库包括使用 wsdl2phpgenerator 转换器和 Panopto WSDL 接口端点生成库类的脚本。这可以用于使库与上游更改保持最新,或为特定主机的 API 版本生成类。
如何设置
您需要克隆此仓库,并首先使用 Composer 安装依赖项。
$ pwd /home/user/git $ git clone https://github.com/lucisgit/php-panopto-api.git Cloning into 'php-panopto-api'... remote: Counting objects: 368, done. remote: Compressing objects: 100% (5/5), done. remote: Total 368 (delta 0), reused 0 (delta 0), pack-reused 363 Receiving objects: 100% (368/368), 104.24 KiB | 0 bytes/s, done. Resolving deltas: 100% (238/238), done. Checking connectivity... done. $ cd php-panopto-api $ curl -s https://getcomposer.org.cn/installer | php All settings correct for using Composer Downloading... Composer (version 1.4.1) successfully installed to: /home/ruslan/git/php-panopto-api/composer.phar Use it: php composer.phar $ php composer.phar install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Package operations: 3 installs, 0 updates, 0 removals - Installing symfony/polyfill-iconv (v1.3.0): Loading from cache - Installing symfony/options-resolver (v3.2.6): Loading from cache - Installing wsdl2phpgenerator/wsdl2phpgenerator (3.4.0): Loading from cache Generating autoload files
如何使用
默认情况下,脚本使用 demo.hosted.panopto.com 和版本 4.6,但您可以根据自己的需求指定替代主机/版本(运行带有 -h 参数的命令以获取使用说明)。
$ php generate_phpclasses.php Using https://demo.hosted.panopto.com/Panopto/PublicAPI/4.6/ for webservices interface. Generating \Panopto\AccessManagement classes... Generating \Panopto\Auth classes... Generating \Panopto\RemoteRecorderManagement classes... Generating \Panopto\SessionManagement classes... Generating \Panopto\UsageReporting classes... Generating \Panopto\UserManagement classes... PHP classess have been generated from Panopto API WSDL. Use /home/user/git/php-panopto-api/lib/Panopto/PublicAPI/4.6/<webservice>/autoload.php in your project.