Skip to content

Instantly share code, notes, and snippets.

@tszym
tszym / youtube-analytics.php
Created July 3, 2014 08:38
Youtube Analytics API - Authentication
<?php
/**
* How to authenticate with OAuth2 by the Google API client
**/
$classLoader = require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Client.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Service/YouTubeAnalytics.php';
@tszym
tszym / youtube-analytics.php
Created July 3, 2014 09:24
Youtube Analytics API - Get metrics
<?php
// ...
if ($client->getAccessToken()) {
// Create analytics service object.
$youtube = new Google_Service_YouTubeAnalytics($client);
try {
// Here we query the API
$analyticsResponse = $youtube->reports->query('channel==UCKVMqeVtKOKxIIqPX84_MKA', '2014-06-25', '2014-06-29',
@tszym
tszym / youtube-data.php
Created July 3, 2014 10:03
Youtube Data API v3 - Authentication
<?php
/**
* How to authenticate with OAuth2 by the Google API client
**/
$classLoader = require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Client.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Service/YouTube.php';
@tszym
tszym / youtube-my-videos.php
Last active August 29, 2015 14:03
Youtube Data API v3 - Get my uploaded videos
<?php
// ...
if ($client->getAccessToken()) {
// Create analytics service object.
$youtube = new Google_Service_YouTube($client);
try {
// Call the channels.list method to retrieve information about the
// currently authenticated user's channel.
@tszym
tszym / youtube-favorite-videos.php
Created July 7, 2014 08:53
Youtube Data API v3 - Get my favorites videos
<?php
// ...
if ($client->getAccessToken()) {
// Create analytics service object.
$youtube = new Google_Service_YouTube($client);
/**
* Retrive favourites videos of the user
@tszym
tszym / youtube-search.php
Created July 7, 2014 09:15
Youtube Data API v3 - Search videos
<?php
// ...
if ($client->getAccessToken()) {
// Create analytics service object.
$youtube = new Google_Service_YouTube($client);
try {
$keySearch = isset($_POST['key']) ? $_POST['key'] : '';
@tszym
tszym / analytics.php
Created July 7, 2014 09:58
Google Analytics API - Authentication
<?php
/**
* How to authenticate with OAuth2 by the Google API client
**/
$classLoader = require __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Client.php';
require_once __DIR__.'/../vendor/google/apiclient/src/Google/Service/Analytics.php';
@tszym
tszym / analytics.php
Created July 7, 2014 11:38
Google Analytics API - Get sessions on time
<?php
// The first step is the authentication, in an other gist
// ...
function runDemo($analytics) {
try {
// Step 2. Get the user's first view (profile) ID.
$profileId = getFirstProfileId($analytics);
@tszym
tszym / account.php
Last active August 29, 2015 14:03
Twitter API - Account data
<?php
/**
* @file
* User has successfully authenticated with Twitter. Access tokens saved to session and DB.
*/
/* Load required lib files. */
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
@tszym
tszym / template.php
Created July 7, 2014 16:09
Twitter API - Tweet data
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Twitter - Get tweet infos in PHP</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
img {border-width: 0}
* {font-family:'Lucida Grande', sans-serif;}
</style>