webedia-arabia/jwplatform

官方 JW Player 客户端 / forked php70

v1.7.0 2020-11-09 16:20 UTC

This package is auto-updated.

Last update: 2024-09-10 00:37:13 UTC


README

JWPlatform PHP 库为 PHP 编写的应用程序提供了方便的访问 JW Platform 管理API的方式。

访问 JW Player 开发者网站 了解 JW Platform API 的更多信息。

要求

PHP 5.6.0 及更高版本。

安装

Composer

您可以通过 Composer 安装绑定。运行以下命令

composer require jwplayer/jwplatform

要使用绑定,请使用 Composer 的 自动加载

require_once('vendor/autoload.php');

手动安装

如果您不希望使用 Composer,您可以下载 最新版本。然后,为了使用绑定,请包含 init.php 文件。

require_once('/path/to/jwplatform-php/init.php');

依赖

绑定需要以下扩展才能正常工作

  • curl,尽管如果您愿意,可以使用自己的非 cURL 客户端

如果您使用 Composer,这些依赖应该会自动处理。如果您手动安装,您需要确保这些扩展可用。

用法

请参阅我们的 文档 了解所有 API 功能。

获取视频元数据

$jwplatform_api = new Jwplayer\JwplatformAPI('INSERT API KEY', 'INSERT API SECRET');

$video_key = 'INSERT VIDEO KEY';
$response = $jwplatform_api->call('/videos/show', array('video_key'=>$video_key));

上传文件

$jwplatform_api = new Jwplayer\JwplatformAPI('INSERT API KEY', 'INSERT API SECRET');

$target_file = 'examples/test.mp4';
$params = array();
$params['title'] = 'PHP API Test Upload';
$params['description'] = 'Video description here';

// Create video metadata
$create_response = json_encode($jwplatform_api->call('/videos/create', $params));
$decoded = json_decode(trim($create_response), TRUE);
$upload_link = $decoded['link'];

$upload_response = $jwplatform_api->upload($target_file, $upload_link);

print_r($upload_response);

获取分析报告

$jwplatform_api = new Jwplayer\JwplatformAPI('API KEY', 'API SECRET', 'REPORTING API KEY');

// set these environment variables
$jwplatform_api_key = $_ENV['JWPLATFORM_API_KEY'];
$jwplatform_api_secret = $_ENV['JWPLATFORM_API_SECRET'];
$reporting_api_key = $_ENV['JWPLATFORM_REPORTING_API_KEY'];

$jwplatform_api = new Jwplayer\JwplatformAPI($jwplatform_api_key, $jwplatform_api_secret, $reporting_api_key);

// params to get to query by embeds by device for a certain date range
$params = array();
$params['start_date'] = '2019-12-01';
$params['end_date'] = '2019-12-31';
$params['dimensions'] = array('device_id');
$params['include_metadata'] = 1;
$params['metrics'] = array(array('operation' => 'sum', 'field' => 'embeds'));
$params['sort'] = array(array('field' => 'embeds', 'order' => 'DESCENDING'));

// Query analytics
$response = json_encode($jwplatform_api->call('/sites/'.$jwplatform_api_key.'/analytics/queries', $params, 'v2'));

print_r(json_decode($response));

有关更多查询示例,请参阅我们的 文档

开发

获取 Composer。例如,在 Mac OS 上

brew install composer

安装依赖

composer install

许可证

JW Platform API 库采用 MIT 许可 发布。