tubecode/tubecode

This package is abandoned and no longer maintained. No replacement package was suggested.

TubeCode - YouTube API Client for PHP

v3.1.1 2016-08-02 17:48 UTC

This package is not auto-updated.

Last update: 2017-01-20 22:57:42 UTC


README

A simple abstraction for the YouTube API - providing a fluent api that is powerful and easy to use.

Installation

Step 1: Composer

From the command line, run:

composer require tubecode/tubecode

Documentation

Authentication

Google APIs use the OAuth 2.0 protocol for authentication and authorization. Tubecode supports common OAuth 2.0 scenarios such as those for web server, and installed applications.

Using OAuth 2.0 for Server to Server Applications

Fundamental knowledge: Google Identity Platform - 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)

Using OAuth 2.0 for Web Server Applications

Fundamental knowledge: Google Identity Platform - OAuth2WebServer

use Tubecode\Auth\WebServer;
use Tubecode\Tubecode;

$serviceAccount = new WebServer($token);

$tubecode = Tubecode::factory($serviceAccount)

$tubecode->httpClient->{get|post|patch|delete}()

Reporting API

The YouTube Reporting API enables developers to schedule reporting jobs and then download generated bulk reports. The API supports a predefined set of reports, each of which contains a comprehensive set of YouTube Analytics data for a channel or content owner.

The steps below explain how to schedule reporting jobs and retrieve reports:

  1. Call the reportTypes()->all() method to retrieve a list of reports that a channel or content owner can retrieve.
  2. Call the jobs()->create() method to identify a report that should be generated for a channel or content owner. You can subsequently use the API's jobs()->list() and jobs()->delete() to retrieve or change the list of reports being generated.
  3. Call the jobs()->reports()->list() method to retrieve a list of reports that have been generated for a particular job. Each resource in the response has access to a download() method from which the report can be downloaded.
$reporting = $tubecode->reporting();

Jobs

A job resource represents a scheduled reporting job. A reporting job identifies a specific report that YouTube generates each day for a particular channel or content owner.

Get Job

Retrieves information about a specific reporting job that has been scheduled for a channel or content owner.

$job = $reporting->jobs()->find("job-id");
Get all Jobs

Lists reporting jobs that have been scheduled for a channel or content owner. Each resource in the response contains an id property, which specifies the ID that YouTube uses to uniquely identify the job. You need that ID to retrieve the list of reports that have been generated for the job or to delete the job.

$jobs = $reporting->jobs()->all();
Create new Job

Creates a reporting job. By creating a reporting job, you are instructing YouTube to generate that report on a daily basis. The report is available within 24 hours of the time that the job is created.

use Tubecode\Services\Reporting\Resources\Job;

$job = $reporting->jobs()->create(new Job("report-type-id", "name"));
Delete Job

Deletes a reporting job.

$reporting->jobs()->delete($job)

$reporting->jobs()->delete($jobs)

$reporting->jobs()->delete(1)

$reporting->jobs()->delete([1,2,3])

Reports

A report resource identifies a specific instance of a report. The resource identifies the period of time for which the report contains data as well as the URL from which the report can be downloaded.

Get Report

Retrieves the metadata for a specific report.

$report = $reporting->jobs()->find("1")->reports()->find(55);
Download Report

Download a specific report.

$data = $reporting->jobs()->find("1")->reports()->find(55)->download();
Get all Reports

Lists reports that have been generated for the specified reporting job.

$reports = $reporting->jobs()->find("1")->reports()->all;

ReportTypes

A reportType resource identifies a specific report that a channel or content owner can retrieve.

Get all ReportTypes

Returns a list of report types that the channel or content owner can retrieve. Each item in the list contains an id property, which identifies the report's ID, and you need this value to schedule a reporting job.

$reportType = $reporting->reportType()->all();

Analytics API

coming later

Data API

coming later

Partner API

coming later

License

The code of this repository is released under the MIT license.

Parts of the Documentation explaining the resources are taken from the Google Developer API Documentation licensed under the Creative Commons Attribution 3.0 License.