【发布时间】:2014-01-06 21:34:59
【问题描述】:
我有一个网站向人们收取观看视频的费用。我正在尝试使用“谷歌驱动器”作为视频的流服务器。我创建了一个帐户服务和私钥,我正在使用 php 库,如下所示:
define('ID_VIDEO', '0B9SXFdezvkZtOE9xVlVNR3U0a1U');
const CLIENT_ID = 'XXXXXXXXXXXXX.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'XXXXXXXXXXXXXX@developer.gserviceaccount.com';
const KEY_FILE = 'XXXXXXXXXXXXXXXXXXXXXX-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("JVideos");
session_start();
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'),
$key)
);
$client->setClientId(CLIENT_ID);
$service = new Google_DriveService($client);
$file = $service->files->get(ID_VIDEO);
$access_toke = json_decode($client->getAccessToken(), TRUE);
$access_toke = $access_toke['access_token'];
?>
<embed width="100%" height="100%" name="plugin" src="<?= urldecode($file['embedLink']);?>&access_token=<?= $access_toke;?>" type="application/x-shockwave-flash" >
问题是:如何在没有任何人登录谷歌的情况下将此视频嵌入我的网站,视频应该通过上面代码中的这个 api 执行的身份验证来观看。当我执行此代码时,谷歌返回给我,这是登录所必需的。
谢谢
【问题讨论】:
标签: video-streaming google-drive-api