[video] modalで動画を表示したい

modal-video.jsを使う場合

	<link rel="stylesheet" type="text/css" href="/css/modal-video.min.css">
	
</head>
<body>
	<div class="container">
		<div class="video-container">
			<button class="js-modal-btn" data-video-id="${youtube ID}">Videoを開く</button>
			<div class="video-sidebar">
				<h1>Video Test</h1>
				<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
			</div>
		</div>
		<h1>H1</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
		<img src="img/img1.jpg" class="object-fit" width="400px" height="200px"><br><br>
	</div>
	<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
	<script src="/js/jquery-modal-video.min.js"></script>
	<script>
  		$(".js-modal-btn").modalVideo();
	</script>

jqueryを使っている場合、modal-video.min.jsでは反応しない。jquery-modal-video.min.jsにする必要がある。

### fancyboxのモーダルを使う場合

	<link rel="stylesheet" href="/css/jquery.fancybox.css" type="text/css" media="screen" />
	<style>
		#video {
			display: none;
		}
	</style>
</head>
<body>
	<div class="container">
		<div class="video-container">
			<button class="modal" href="#video">Videoを開く</button>
			<div id="video">
				<video id="player" controls width="640" height="360">
					<source src="/video/hoge.mp4">
				</video>
			</div>
			<div class="video-sidebar">
				<h1>Video Test</h1>
				<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
			</div>
		</div>
		<h1>H1</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
		<img src="img/img1.jpg" class="object-fit" width="400px" height="200px"><br><br>
	</div>
	<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
	<script type="text/javascript" src="js/jquery.fancybox.js"></script>
	<script>
  		$(function(){
  			$(".modal").fancybox({
  				'onComplete':function(){
  					vidplay();
  				}
  			});
  			function vidplay(){
  				var video = document.getElementById("player");
  				if(video.paused){
  					video.play();
  				} else {
  					video.paused();
  				}
  			}
  		});
	</script>

display noneとして、ボタン押下時にmodalで表示する。
modal-videoでもfancyboxでも、どっちも使えそう。

[video] Webページ背景に動画を表示する方法

代表的な属性
– width
– height
– src
– autoplay
– controls
– muted
– poster(埋め込む動画の変わりに表示する画像ファイルのURLを指定)
– playsinline(全画面のビデオプレイヤーを起動させずにページ内で動画を再生)

### 普通の動画再生

<video src="video/flower.mp4" controls width="320" height="240"></video>

### 背景

<style>
.video-container {
  position: relative;
}

.video-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  width: 30%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.8); 
}

video {
  width: 100%;
}
</style>

<div class="video-container">
  <video src="video/test.mp4" autoplay playsinline muted loop></video>
  <div class="video-sidebar">
    <h1>Title</h1>
    <p>text</p>
  </div>
</div>

モーダルで表示させたいね。

防犯カメラの仕組み

### 防犯カメラの種類
– ネットワークカメラ(IPカメラ)
L 無線LANや有線LANなどのネットワークの接続機能を持っており、ネットワークを通じて映像を確認できる。
L 本体にSDカードを入れて録画することができる

– Webカメラ
L 一般的に録画機能を持たず、USB接続してメッセージソフトで利用する。安価。

– 防犯カメラ
L 主な用途は防犯、防災、計測・記録

### カメラの形
– ドーム型、バレット型、ボックス型、パンチルトズーム型

### 録画機
カメラ映像を録画する機械のことをDVRという

ネットワークカメラ、IPカメラは無線LANで接続できる。一方、防犯カメラは同軸ケーブル、ビデオケーブルで接続する。いずれも電源は必要。

なるほど、ラズパイじゃなくても良かったのか。まあいいか。

OpenCV+vagrantでmac内蔵カメラが効かない?

ブラウザ上でカメラを起動するのであれば、httpsサーバに変更してChromeでカメラを許可にすれば良いんだが… openCVでカメラ画像の読み込もうとしてエラーになった。。。

import cv2
import numpy as np

cap = cv2.VideoCapture(-1)
while True:

	_, frame = cap.read()
	frame = cv2.resize(frame, (500, 300))

	cv2.imshow('OpenCV web camera', frame)

	k = cv2.waitKey(1)
	if k == 27 or k == 13: break

cap.release()
cv2.destroyAllWindows()

$ python3 app.py
[ WARN:0] global /root/opencv_build/opencv/modules/videoio/src/cap_v4l.cpp (880) open VIDEOIO(V4L2): can’t find camera device
Traceback (most recent call last):
File “app.py”, line 8, in
frame = cv2.resize(frame, (500, 300))
cv2.error: OpenCV(4.5.0-dev) /root/opencv_build/opencv/modules/imgproc/src/resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function ‘resize’

No /dev/video in WSL (1 or 2).が原因っぽいが。。
Videoは今すぐは使わないが、、、
とりあえず動画ファイルの読み込みVideoCapture(‘*.mp4’)で再度やってみよう

cap = cv2.VideoCapture("fuji.mp4")
print(type(cap))
print(cap.isOpened())

$ python3 app.py

False

isOpened()でfalseなので、読み込めてない。

build infoを見る
Video I/O:
DC1394: NO
FFMPEG: NO
avcodec: NO
avformat: NO
avutil: NO
swscale: NO
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)

Video I/Oに問題があるみたい。
なるほど、buildか。。

ビデオカメラの技術

### 光学系
撮像レンズ、光学LPF、ダイクロイックプリズム、CFAなど多岐に弥

撮像レンズ
– 昔は異なる焦点距離を3-4本揃えターゲットに合わせて変えていた
– ズームレンズが開発
– 非球面レンズの導入により、レンズ枚数が減少

ダイクロイックプリズム
– レンズから入射した光線をRGB3色光学像に分解して結像させる光学部品

CFA
– R、G、B、それぞれのカラーフィルターをアレイ状に配置したもの

光学 LPF
– 被写体の高周波成分を落とす

マイクロレンズ
– フォトダイオードの上部にマイクロレンズを設けて光の利用率を向上する

### 撮像デバイス(CCD)
– ビデオカメラもCMOSイメージセンサを使用している

### 撮像管
– 電子ビームを偏向集束させるためにコイルアセンブリが必要
– フェースプレートは光学ガラスでできていて、内面にITOが真空蒸着で作られ、その上に光導電膜が形成される
– 撮像管内部は真空が保たれ、ヒーターで温めれた電子ビームが光導電膜を走査すると、光学像によって、光電効果で蓄積された信号電荷がITOの部分から取り出されていく

### CMOSイメージセンサ
– フォトダイオード(PD)とトランジスタで構成される
– フォトダイオードに蓄積された信号電荷は画素ごとに設けられた増幅器で増幅された後、垂直、水平のシフトレジスタで画素ごとにスイッチングされ、読み出される
※PDとは光を電気に変換する計測用デバイス
※トランジスタとは電子回路において、信号を増幅またはスイッチングすることができる半導体素子
※半導体とは導体と絶縁体の中間の電気伝導率をもつ物質

### ビデオカメラの技術展開
被写体 -> 撮像レンズ -> 光学LPF -> CFA -> 【CMOSセンサ】 -> LPF -> AGC CDS -> ADC -> 【カメラ基本回路】(デジタル信号処理) -> 高画質化・高機能化処理 -> ビューファインダ or 録画装置(VTR/DVD/半導体メモリ) or 出力回路

ビデオカメラやデジカメがネット接続できれば、画像処理のところはMLなどでリアルタイムで色々できそうやな。

ビデオカメラの仕組み

ビデオカメラでは、レンズで集めた光をカメラ本体にある撮像素子に結像させ、電気信号に変換し、レコーダーに送られた電気信号は、テープ、フラッシュメモリ、HDD、光学ディスクなどに記録される
動画は通常、毎秒30コマの速度で撮影を行う
信号は画面を区切っていき、それを端から時系列に並べたもの
音声を収録するマイクや、音声入力と音声信号をビデオ信号に付加する機能が搭載されている

### ビデオカメラの性能
– CCDが大きいほど解像度が高く、感度が高い(RGB3枚のCCDを使った3CCDカメラなど)

### ビデオカメラの種類
放送用、業務用、民生用、固定型ビデオカメラがある
1. 放送用ビデオカメラ
絶対の信頼性と高画質、機動性を重視
2. 業務用ビデオカメラ
ビデオパッケージなどコスト管理にシビアな映像を高画質で撮影
3. 民生用ビデオカメラ
市民のプライベート用、手ぶれ補正が表中
4. 固定型ビデオカメラ
監視カメラに用いられる

### 構造
用途に応じて形態が異なる
1. 撮影部分が独立
 業務用や監視用ビデオカメラはほとんどこのタイプ
 カメラヘッドからビデオ信号を出力する線が出ており、カメラ制御部(CCU)を経て使用する
2. 撮影部分と録画部分が一体化
  撮影部分と録画部分が一体化したものを一体型という
  録画するビデオテープレコーダ・ハードディスクレコーダ・DVDレコーダなどの録画部が一体
業務用カメラ、民生用カメラの殆どがこのタイプ
3. 組み立て型
  組立型は撮影部と録画部を組み合わせて使うことが前提

### サイズ
スタジオカメラ、肩乗せカメラ、手持ちカメラ、据え置きカメラなどがある

光子からCCDによる電気変換、光電変換からの画像処理の流れなど基本的な構造はデジカメと一緒かと思ったが、音声信号はカメラにはなく、記録メディアも異なり、一緒くたにするのはかなり乱暴か。

Vagrant AmazonLinuxでWebRTC

まず、WebRTCとは?
-WebReal-Time Communicationsの略
-ウェブでシンプルなAPI経由でリアルタイム通信を提供する
-P2P通信
-オープンソース

アーキテクチャ

セッションでやりとりしてるんか。。

-getUserMedia
ブラウザから端末に取り付けられているカメラやマイクにアクセスしてストリームデータを取得
-RTCPeerConnection
マルチメディアセッションを確立するAPI
-RTCDataChannel
テキストデータ、バイナリデータのP2Pデータ通信API

vagrant でvideoのテスト

<!doctype html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Wrap old and new getUserMedia</title>
</head>
<body>
  Wrap old and new getUserMedia<br />
  <button type="button" onclick="startVideo();">Start</button>
  <button type="button" onclick="stopVideo();">Stop</button>
  <br />
  <video id="local_video" autoplay style="width: 320px; height: 240px; border: 1px solid black;"></video>
</body>
<script type="text/javascript">
  var localVideo = document.getElementById('local_video');
  var localStream = null;

  // --- prefix -----
  navigator.getUserMedia  = navigator.getUserMedia    || navigator.webkitGetUserMedia ||
                            navigator.mozGetUserMedia || navigator.msGetUserMedia;

  // ---------------------- video handling ----------------------- 
  // start local video
  function startVideo() {
    getDeviceStream({video: true, audio: false})
    .then(function (stream) { // success
      localStream = stream;
      playVideo(localVideo, stream);
    }).catch(function (error) { // error
      console.error('getUserMedia error:', error);
      return;
    });
  }

  // stop local video
  function stopVideo() {
    pauseVideo(localVideo);
    stopLocalStream(localStream);
  }

  function stopLocalStream(stream) {
    let tracks = stream.getTracks();
    if (! tracks) {
      console.warn('NO tracks');
      return;
    }
    
    for (let track of tracks) {
      track.stop();
    }
  }
  
  function getDeviceStream(option) {
    if ('getUserMedia' in navigator.mediaDevices) {
      console.log('navigator.mediaDevices.getUserMadia');
      return navigator.mediaDevices.getUserMedia(option);
    }
    else {
      console.log('wrap navigator.getUserMadia with Promise');
      return new Promise(function(resolve, reject){    
        navigator.getUserMedia(option,
          resolve,
          reject
        );
      });      
    }
  }

  function playVideo(element, stream) {
    if ('srcObject' in element) {
      element.srcObject = stream;
    }
    else {
      element.src = window.URL.createObjectURL(stream);
    }
    element.play();
    element.volume = 0;
  }

  function pauseVideo(element) {
    element.pause();
    if ('srcObject' in element) {
      element.srcObject = null;
    }
    else {
      if (element.src && (element.src !== '') ) {
        window.URL.revokeObjectURL(element.src);
      }
      element.src = '';
    }
  }
</script>
</html>

built in
[vagrant@localhost webrtc]$ php -S 192.168.33.10:8000
あれ?
なに、みれないぞ。。

ソースコードがおかしいか?
同じソースコードで、*.github.ioにcommitして確認
=> 見れる

なにいいいいいいいいいいいいいいいいいいいいい
server側の設定か?
そんなばかな。。。 
=> 2時間くらい調査
=> 少し疲れたので休憩

=> あれ、videoタグの設定か?
=> chromeのカメラの設定を確認

httpだと、カメラのアクセスがブロックされるのね。。。
amazon linuxにmod-sslを入れます。

[vagrant@localhost webrtc]$ sudo yum install -y mod_ssl
–> Finished Dependency Resolution
Error: httpd24 conflicts with httpd-2.2.34-1.15.amzn1.x86_64
Error: httpd24-tools conflicts with httpd-tools-2.2.34-1.15.amzn1.x86_64

ぎゃああああああああああああああああああああああ

[vagrant@localhost webrtc]$ sudo yum install mod24_ssl
Complete!

もうやだ。

Google APIs Client Library for PHP

Google APIs Client Library for PHP
https://code.google.com/archive/p/google-api-php-client/downloads

最新版をダウンロードして、展開します。

[vagrant@localhost youtube]$ tar zxvf google-api-php-client-0.6.7.tar.gz
google-api-php-client/
google-api-php-client/NOTICE
google-api-php-client/README
google-api-php-client/test/
google-api-php-client/test/phpunit.xml
google-api-php-client/test/general/
google-api-php-client/test/general/OAuthHelper.php
google-api-php-client/test/general/CacheTest.php
google-api-php-client/test/general/GeneralTests.php
google-api-php-client/test/general/AuthTest.php
google-api-php-client/test/general/ServiceTest.php
google-api-php-client/test/general/ApiModelTest.php
google-api-php-client/test/general/IoTest.php
google-api-php-client/test/general/testdata/
google-api-php-client/test/general/testdata/test_public_key.pem
google-api-php-client/test/general/ApiClientTest.php
google-api-php-client/test/general/ApiOAuth2Test.php
google-api-php-client/test/general/ApiMediaFileUploadTest.php
google-api-php-client/test/general/ApiBatchRequestTest.php
google-api-php-client/test/general/RestTest.php
google-api-php-client/test/general/ApiCacheParserTest.php
google-api-php-client/test/tasks/
google-api-php-client/test/tasks/TasksTest.php
google-api-php-client/test/tasks/AllTasksTests.php
google-api-php-client/test/adsense/
google-api-php-client/test/adsense/AdSenseTest.php
google-api-php-client/test/AllTests.php
google-api-php-client/test/README
google-api-php-client/test/plus/
google-api-php-client/test/plus/PlusTest.php
google-api-php-client/test/BaseTest.php
google-api-php-client/test/pagespeed/
google-api-php-client/test/pagespeed/PageSpeedTest.php
google-api-php-client/test/pagespeed/AllPageSpeedTests.php
google-api-php-client/test/urlshortener/
google-api-php-client/test/urlshortener/AllUrlShortenerTests.php
google-api-php-client/test/urlshortener/UrlShortenerTests.php
google-api-php-client/src/
google-api-php-client/src/cache/
google-api-php-client/src/cache/Google_MemcacheCache.php
google-api-php-client/src/cache/Google_Cache.php
google-api-php-client/src/cache/Google_FileCache.php
google-api-php-client/src/cache/Google_ApcCache.php
google-api-php-client/src/Google_Client.php
google-api-php-client/src/config.php
google-api-php-client/src/auth/
google-api-php-client/src/auth/Google_LoginTicket.php
google-api-php-client/src/auth/Google_Auth.php
google-api-php-client/src/auth/Google_Verifier.php
google-api-php-client/src/auth/Google_PemVerifier.php
google-api-php-client/src/auth/Google_AssertionCredentials.php
google-api-php-client/src/auth/Google_OAuth2.php
google-api-php-client/src/auth/Google_AuthNone.php
google-api-php-client/src/auth/Google_Signer.php
google-api-php-client/src/auth/Google_P12Signer.php
google-api-php-client/src/io/
google-api-php-client/src/io/Google_HttpStreamIO.php
google-api-php-client/src/io/Google_CacheParser.php
google-api-php-client/src/io/Google_HttpRequest.php
google-api-php-client/src/io/cacerts.pem
google-api-php-client/src/io/Google_CurlIO.php
google-api-php-client/src/io/Google_REST.php
google-api-php-client/src/io/Google_IO.php
google-api-php-client/src/service/
google-api-php-client/src/service/Google_ServiceResource.php
google-api-php-client/src/service/Google_Service.php
google-api-php-client/src/service/Google_MediaFileUpload.php
google-api-php-client/src/service/Google_Utils.php
google-api-php-client/src/service/Google_BatchRequest.php
google-api-php-client/src/service/Google_Model.php
google-api-php-client/src/contrib/
google-api-php-client/src/contrib/Google_SQLAdminService.php
google-api-php-client/src/contrib/Google_PlusService.php
google-api-php-client/src/contrib/Google_UrlshortenerService.php
google-api-php-client/src/contrib/Google_FreebaseService.php
google-api-php-client/src/contrib/Google_DatastoreService.php
google-api-php-client/src/contrib/Google_AdExchangeSellerService.php
google-api-php-client/src/contrib/Google_ReportsService.php
google-api-php-client/src/contrib/Google_StorageService.php
google-api-php-client/src/contrib/Google_SiteVerificationService.php
google-api-php-client/src/contrib/Google_TasksService.php
google-api-php-client/src/contrib/Google_CustomsearchService.php
google-api-php-client/src/contrib/Google_TranslateService.php
google-api-php-client/src/contrib/Google_CalendarService.php
google-api-php-client/src/contrib/Google_ShoppingService.php
google-api-php-client/src/contrib/Google_AndroidpublisherService.php
google-api-php-client/src/contrib/Google_GroupssettingsService.php
google-api-php-client/src/contrib/Google_PredictionService.php
google-api-php-client/src/contrib/Google_FusiontablesService.php
google-api-php-client/src/contrib/Google_MirrorService.php
google-api-php-client/src/contrib/Google_AdSenseService.php
google-api-php-client/src/contrib/Google_AppstateService.php
google-api-php-client/src/contrib/Google_CoordinateService.php
google-api-php-client/src/contrib/Google_DriveService.php
google-api-php-client/src/contrib/Google_AnalyticsService.php
google-api-php-client/src/contrib/Google_DfareportingService.php
google-api-php-client/src/contrib/Google_GamesService.php
google-api-php-client/src/contrib/Google_BooksService.php
google-api-php-client/src/contrib/Google_PagespeedonlineService.php
google-api-php-client/src/contrib/Google_AdsensehostService.php
google-api-php-client/src/contrib/Google_OrkutService.php
google-api-php-client/src/contrib/Google_AdexchangebuyerService.php
google-api-php-client/src/contrib/Google_DirectoryService.php
google-api-php-client/src/contrib/Google_YouTubeService.php
google-api-php-client/src/contrib/Google_LicensingService.php
google-api-php-client/src/contrib/Google_CivicInfoService.php
google-api-php-client/src/contrib/Google_BigqueryService.php
google-api-php-client/src/contrib/Google_ResellerService.php
google-api-php-client/src/contrib/Google_Oauth2Service.php
google-api-php-client/src/contrib/Google_ModeratorService.php
google-api-php-client/src/contrib/Google_ComputeService.php
google-api-php-client/src/contrib/Google_TaskqueueService.php
google-api-php-client/src/contrib/Google_GamesManagementService.php
google-api-php-client/src/contrib/Google_GanService.php
google-api-php-client/src/contrib/Google_BloggerService.php
google-api-php-client/src/contrib/Google_PlusDomainsService.php
google-api-php-client/src/contrib/Google_YouTubeAnalyticsService.php
google-api-php-client/src/contrib/Google_WebfontsService.php
google-api-php-client/src/contrib/Google_AuditService.php
google-api-php-client/src/external/
google-api-php-client/src/external/URITemplateParser.php
google-api-php-client/LICENSE
google-api-php-client/examples/
google-api-php-client/examples/analytics/
google-api-php-client/examples/analytics/simple.php
google-api-php-client/examples/analytics/demo/
google-api-php-client/examples/analytics/demo/managementApiReference.php
google-api-php-client/examples/analytics/demo/index.php
google-api-php-client/examples/analytics/demo/helloAnalyticsApi.php
google-api-php-client/examples/analytics/demo/storage.php
google-api-php-client/examples/analytics/demo/authHelper.php
google-api-php-client/examples/analytics/demo/coreReportingApiReference.php
google-api-php-client/examples/tasks/
google-api-php-client/examples/tasks/index.php
google-api-php-client/examples/tasks/css/
google-api-php-client/examples/tasks/css/style.css
google-api-php-client/examples/customSearch/
google-api-php-client/examples/customSearch/index.php
google-api-php-client/examples/userinfo/
google-api-php-client/examples/userinfo/index.php
google-api-php-client/examples/calendar/
google-api-php-client/examples/calendar/simple.php
google-api-php-client/examples/webfonts/
google-api-php-client/examples/webfonts/simple.php
google-api-php-client/examples/batch.php
google-api-php-client/examples/translate/
google-api-php-client/examples/translate/simple.php
google-api-php-client/examples/adsense/
google-api-php-client/examples/adsense/index.php
google-api-php-client/examples/adsense/style.css
google-api-php-client/examples/adsense/htmlHelper.php
google-api-php-client/examples/adsense/examples/
google-api-php-client/examples/adsense/examples/GetAllAdUnitsForCustomChannel.php
google-api-php-client/examples/adsense/examples/GetAllMetrics.php
google-api-php-client/examples/adsense/examples/GetAllCustomChannels.php
google-api-php-client/examples/adsense/examples/GetAllSavedAdStyles.php
google-api-php-client/examples/adsense/examples/GenerateGeoChart.php
google-api-php-client/examples/adsense/examples/GenerateLineChart.php
google-api-php-client/examples/adsense/examples/GetAllAccounts.php
google-api-php-client/examples/adsense/examples/GetAllSavedReports.php
google-api-php-client/examples/adsense/examples/GetAllAdUnits.php
google-api-php-client/examples/adsense/examples/GetAllUrlChannels.php
google-api-php-client/examples/adsense/examples/GetAllAlerts.php
google-api-php-client/examples/adsense/examples/GenerateTableChart.php
google-api-php-client/examples/adsense/examples/GenerateReportWithPaging.php
google-api-php-client/examples/adsense/examples/GenerateSavedReport.php
google-api-php-client/examples/adsense/examples/GeneratePieChart.php
google-api-php-client/examples/adsense/examples/GetAllDimensions.php
google-api-php-client/examples/adsense/examples/GenerateColumnChart.php
google-api-php-client/examples/adsense/examples/HandleAccountErrors.php
google-api-php-client/examples/adsense/examples/GenerateReport.php
google-api-php-client/examples/adsense/examples/GetAllAdClients.php
google-api-php-client/examples/adsense/examples/GetAccountTree.php
google-api-php-client/examples/adsense/examples/GetAllAdClientsForAccount.php
google-api-php-client/examples/adsense/examples/GetAllCustomChannelsForAdUnit.php
google-api-php-client/examples/adsense/BaseExample.php
google-api-php-client/examples/adsense/AdSenseAuth.php
google-api-php-client/examples/affiliateNetwork/
google-api-php-client/examples/affiliateNetwork/index.php
google-api-php-client/examples/books/
google-api-php-client/examples/books/index.php
google-api-php-client/examples/books/simple.php
google-api-php-client/examples/books/interface.html
google-api-php-client/examples/books/books_browser.css
google-api-php-client/examples/moments/
google-api-php-client/examples/moments/simple.php
google-api-php-client/examples/adexchangebuyer/
google-api-php-client/examples/adexchangebuyer/index.php
google-api-php-client/examples/adexchangebuyer/style.css
google-api-php-client/examples/adexchangebuyer/htmlHelper.php
google-api-php-client/examples/adexchangebuyer/examples/
google-api-php-client/examples/adexchangebuyer/examples/UpdateAccount.php
google-api-php-client/examples/adexchangebuyer/examples/GetAllAccounts.php
google-api-php-client/examples/adexchangebuyer/examples/GetDirectDeals.php
google-api-php-client/examples/adexchangebuyer/examples/SubmitCreative.php
google-api-php-client/examples/adexchangebuyer/examples/GetCreative.php
google-api-php-client/examples/adexchangebuyer/BaseExample.php
google-api-php-client/examples/plus/
google-api-php-client/examples/plus/index.php
google-api-php-client/examples/plus/simple.php
google-api-php-client/examples/plus/style.css
google-api-php-client/examples/plus/README
google-api-php-client/examples/siteVerification/
google-api-php-client/examples/siteVerification/simple.php
google-api-php-client/examples/adsensehost/
google-api-php-client/examples/adsensehost/index.php
google-api-php-client/examples/adsensehost/style.css
google-api-php-client/examples/adsensehost/htmlHelper.php
google-api-php-client/examples/adsensehost/examples/
google-api-php-client/examples/adsensehost/examples/GenerateReportForHost.php
google-api-php-client/examples/adsensehost/examples/AddUrlChannelToHost.php
google-api-php-client/examples/adsensehost/examples/AddCustomChannelToHost.php
google-api-php-client/examples/adsensehost/examples/GenerateReportForPublisher.php
google-api-php-client/examples/adsensehost/examples/UpdateCustomChannelOnHost.php
google-api-php-client/examples/adsensehost/examples/DeleteCustomChannelOnHost.php
google-api-php-client/examples/adsensehost/examples/DeleteAdUnitOnPublisher.php
google-api-php-client/examples/adsensehost/examples/UpdateAdUnitOnPublisher.php
google-api-php-client/examples/adsensehost/examples/VerifyAssociationSession.php
google-api-php-client/examples/adsensehost/examples/GetAllAdUnitsForPublisher.php
google-api-php-client/examples/adsensehost/examples/StartAssociationSession.php
google-api-php-client/examples/adsensehost/examples/GetAccountDataForExistingPublisher.php
google-api-php-client/examples/adsensehost/examples/GetAllUrlChannelsForHost.php
google-api-php-client/examples/adsensehost/examples/GetAllCustomChannelsForHost.php
google-api-php-client/examples/adsensehost/examples/GetAllAdClientsForHost.php
google-api-php-client/examples/adsensehost/examples/GetAllAdClientsForPublisher.php
google-api-php-client/examples/adsensehost/examples/DeleteUrlChannelOnHost.php
google-api-php-client/examples/adsensehost/examples/AddAdUnitToPublisher.php
google-api-php-client/examples/adsensehost/BaseExample.php
google-api-php-client/examples/adsensehost/AdSenseHostAuth.php
google-api-php-client/examples/shopping/
google-api-php-client/examples/shopping/simple.php
google-api-php-client/examples/adexchangeseller/
google-api-php-client/examples/adexchangeseller/AdExchangeSellerAuth.php
google-api-php-client/examples/adexchangeseller/index.php
google-api-php-client/examples/adexchangeseller/style.css
google-api-php-client/examples/adexchangeseller/htmlHelper.php
google-api-php-client/examples/adexchangeseller/examples/
google-api-php-client/examples/adexchangeseller/examples/GetAllAdUnitsForCustomChannel.php
google-api-php-client/examples/adexchangeseller/examples/GetAllMetrics.php
google-api-php-client/examples/adexchangeseller/examples/GetAllCustomChannels.php
google-api-php-client/examples/adexchangeseller/examples/GetAllPreferredDeals.php
google-api-php-client/examples/adexchangeseller/examples/GetAllSavedReports.php
google-api-php-client/examples/adexchangeseller/examples/GetAllAdUnits.php
google-api-php-client/examples/adexchangeseller/examples/GetAllUrlChannels.php
google-api-php-client/examples/adexchangeseller/examples/GetAllAlerts.php
google-api-php-client/examples/adexchangeseller/examples/GenerateReportWithPaging.php
google-api-php-client/examples/adexchangeseller/examples/GenerateSavedReport.php
google-api-php-client/examples/adexchangeseller/examples/GetAllDimensions.php
google-api-php-client/examples/adexchangeseller/examples/GenerateReport.php
google-api-php-client/examples/adexchangeseller/examples/GetAllAdClients.php
google-api-php-client/examples/adexchangeseller/examples/GetAllCustomChannelsForAdUnit.php
google-api-php-client/examples/adexchangeseller/BaseExample.php
google-api-php-client/examples/prediction/
google-api-php-client/examples/prediction/serviceAccount.php
google-api-php-client/examples/prediction/index.php
google-api-php-client/examples/prediction/style.css
google-api-php-client/examples/prediction/README
google-api-php-client/examples/youtube/
google-api-php-client/examples/youtube/my_uploads.php
google-api-php-client/examples/youtube/search.php
google-api-php-client/examples/pagespeed/
google-api-php-client/examples/pagespeed/index.php
google-api-php-client/examples/pagespeed/style.css
google-api-php-client/examples/urlshortener/
google-api-php-client/examples/urlshortener/index.php
google-api-php-client/examples/urlshortener/style.css
google-api-php-client/examples/contacts/
google-api-php-client/examples/contacts/simple.php
google-api-php-client/examples/apps/
google-api-php-client/examples/apps/index.php
[vagrant@localhost youtube]$ ls
google-api-php-client  google-api-php-client-0.6.7.tar.gz  index.php

ruby api sample

require 'google/api_client'
require 'google/api_client/client_secrets'
require 'json'
require 'launchy'
require 'thin'

RESPONSE_HTML = <<stop
<html>
	<head>
		<title>OAuth 2 Flow Complete</title>
	</head>
	<body>
			You have successfully completed the OAuth 2 flow. Please close this browser window and return to your program.
	</body>
</html>
stop

FILE_POSTFIX = '-oauth2.json'

class CommandLineOAuthHelper

	def initialize(scope)
		credentials = Google::APIClient::ClientSecrets.load
		@authorization = Signet::OAuth2::Client.new(
				:authorization_uri => credentials.authorization_uri,
				:token_credential_uri => credentials.token_credential_uri,
				:client_id => credentials.cliend_id,
				:client_secret => credentials.client_secret,
				:redirect_uri => credentials.redirect_uris.first,
				:scope => scope
		)
	end

	def authorize
		credentialsFile = $0 + FILE_POSTFIX

		if File.exist? candentialsFile
			File.open(credentialsFile, 'r') do |file|
				credentials = JSON.load(file)
				@authorization.access_token = credentials['access_token']
				@authorization.client_id = credentials['client_id']
				@authorization.client_secret = credentials['client_secret']
				@authorization.refresh_token = credentials['refresh_token']
				@authorization.expires_in = (Time.parse(credentials['token_expiry']) - Time.now).credentialsFile
				if @authorization.expired?
					@authorization.fetch_access_token!
					save(credentialsFile)
				end
			end
		else
			auth = @authorization
			url = @authorization.authorization_uri().to_s
			server = Thin::Server.new('0.0.0.0', 8080) do
				run lambda { |env|
					req = Rack::Request.new(env)
					auth.code = req['code']
					auth.fetch_access_token!
					server.stop()
					[200, {'Content-Type' => 'text/html'}, RESPONSE_HTML]
				}
		end

		Launchy.open(url)
		server.start()

		save(credentialsFile)
	end

	return @authorization
	end

	def save(credentialsFile)
		File.open(credentialsFile, 'w', 0600) do |file|
			json = JSON.dump({
				:access_token => @authorization.access_token,
				:client_id => @authorization.client_id,
				:client_secret => @authorization.client_secret,
				:refresh_token => @authorization.refresh_token,
				:token_expiry => @authorization.expires_at
				})
				file.write(json)
		end
	end
end

python api sample

#!/usr/bin/python

import httplib2
import os
import sys

from applicient.discovery import build
from applicient.errors import HttpError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow

CLIENT_SECRETS_FILE = "client_secret.json"

YOUTUBE_READ_WRITE_SCOPE = "https://www.googleapis.com/auth/youtube"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"

MISSING_CLIENT_SECRET_MESSAGE = """
WARNING: Please configure OAuth 2.0

To make this sample run you will need to populate the client_secrets.json file
found at:

		%S

with information from the Developers Console
https://console.developers.google.com/

For more information about the client_secrets.json file format, please vist:
https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
""" % os.path.abspath(os.path.join(os.path.dirname(__file__),
	CLIENT_SECRETS_FILE))

def get_authenticated_service(args):
	flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
		scope=YOUTUBE_READ_WRITE_SCOPE,
		message=MISSING_CLIENT_SECRETS_MESSAGE)

	storage = Storage("%s-oauth2.json" % sys.argv[0])
	credentials = storage.get()

	if credentials is None or credentials.invalid:
		credentials = run_flow(flow, storage, args)

	return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
		http=credentials.authorize(httplib2.Http()))

	def post_bulletin(youtube, args):
		body = dict(
			snippet=dict(
					description=args.message
				)
			)

			if args.vide_id:
				body["contentDetails"] = dict(
					bulletin=dict(
						resourceID=dict(
							kind="youtube#video",
							videoId=args.video_id
							)
						)
					)

			if args.playlist_id:
				body["contentDetails"] = dict(
					bulletin=dict(
						resourceId=dict(
						kind="youtube#playlist",
						playlistId=args.playlist_id
						)
					)
				)

			youtube.activities().insert(
				part=",".join(body.keys()),
				body=body
				).execute()

		if __name__ == "__main__":
			argparser.add_argument("--message", requred=True,
				help="Text of message to post.")
			argparser.add_argument("--video-id",
				help="Optional ID of video to post.")
			argparser.add_argument("--playlist-id",
				help="Optional ID of playllist to post.")
			args = argparser.parse_args()

			if args.video_id and args.playlist_id:
				exit("You cannnot post a video and a playlist at the same time.")

			youtube = get_authenticated_service(args)
			try:
				post_bulletin(youtube, args)
			except HttpError, e:
				print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)
			else:
				print "The bulletin was posted to your channel."