tubecode / tubecode
TubeCode - PHP的YouTube API客户端
Requires
- php: >=5.5.9
- google/apiclient: ^2.0
- tightenco/collect: ^5.2
This package is not auto-updated.
Last update: 2017-01-20 22:57:42 UTC
README
YouTube API的一个简单抽象 - 提供一个强大且易于使用的流畅API。
安装
步骤1: Composer
在命令行中运行
composer require tubecode/tubecode
文档
认证
Google API使用OAuth 2.0协议进行认证和授权。Tubecode支持常见的OAuth 2.0场景,如网络服务器和安装的应用程序。
使用OAuth 2.0为服务器到服务器应用程序
基础知识:Google身份平台 - OAuth2ServiceAccount
use Tubecode\Auth\ServiceAccount; use Tubecode\Tubecode; $serviceAccountCredentials = file_get_contents('google-service-account-credentials.json'); $serviceAccount = new ServiceAccount($serviceAccountCredentials); $tubecode = Tubecode::factory($serviceAccount)
使用OAuth 2.0为网络服务器应用程序
基础知识:Google身份平台 - OAuth2WebServer
use Tubecode\Auth\WebServer; use Tubecode\Tubecode; $serviceAccount = new WebServer($token); $tubecode = Tubecode::factory($serviceAccount) $tubecode->httpClient->{get|post|patch|delete}()
报告API
YouTube报告API允许开发者为报告作业计划时间并下载生成的批量报告。API支持一组预定义的报告,每个报告都包含频道或内容所有者的YouTube分析数据的综合集。
以下步骤说明了如何安排报告作业和检索报告
- 调用reportTypes()->all()方法以检索频道或内容所有者可以检索的报告列表。
- 调用jobs()->create()方法以标识应为频道或内容所有者生成报告的报告。您随后可以使用API的jobs()->list()和jobs()->delete()来检索或更改正在生成的报告列表。
- 调用jobs()->reports()->list()方法以检索特定作业已生成的报告列表。每个响应中的资源都可以访问download()方法,从中可以下载报告。
$reporting = $tubecode->reporting();
作业
作业资源表示计划好的报告作业。报告作业标识YouTube每天为特定频道或内容所有者生成的特定报告。
获取作业
检索为频道或内容所有者安排的特定报告作业的信息。
$job = $reporting->jobs()->find("job-id");
获取所有作业
列出为频道或内容所有者安排的报告作业。响应中的每个资源都包含一个id属性,该属性指定YouTube用于唯一标识作业的ID。您需要该ID来检索为作业生成的报告列表或删除作业。
$jobs = $reporting->jobs()->all();
创建新作业
创建一个报告作业。通过创建报告作业,您指示YouTube每天生成该报告。报告将在作业创建后24小时内可用。
use Tubecode\Services\Reporting\Resources\Job; $job = $reporting->jobs()->create(new Job("report-type-id", "name"));
删除作业
删除一个报告作业。
$reporting->jobs()->delete($job) $reporting->jobs()->delete($jobs) $reporting->jobs()->delete(1) $reporting->jobs()->delete([1,2,3])
报告
报告资源标识了一个特定报告的实例。该资源标识了报告包含数据的期间以及可以从中下载报告的URL。
获取报告
检索特定报告的元数据。
$report = $reporting->jobs()->find("1")->reports()->find(55);
下载报告
下载特定报告。
$data = $reporting->jobs()->find("1")->reports()->find(55)->download();
获取所有报告
列出为指定的报告作业生成的报告。
$reports = $reporting->jobs()->find("1")->reports()->all;
报告类型
报告类型资源标识了频道或内容所有者可以检索的特定报告。
获取所有报告类型
返回频道或内容所有者可以检索的报告类型列表。列表中的每个项目都包含一个id属性,该属性标识报告的ID,您需要此值来安排报告作业。
$reportType = $reporting->reportType()->all();
分析API
稍后提供
数据API
稍后提供
合作伙伴API
稍后提供
许可证
此存储库的代码在MIT许可证下发布。
解释资源的文档部分摘自Google Developer API文档,该文档在Creative Commons Attribution 3.0许可证下授权。