Youtube API PHP Zend GData直接上传 - php

我正在创建一个Web应用程序,代表用户将网站从服务器上载到youtube。

我遵循Google的PHP文档,并成功获取了会话令牌。

这是我用来检索会话令牌的代码:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_AuthSub');

$singleUseToken = $_GET['token'];

$sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);  

echo $sessionToken;

我的目的是将每个用户的会话令牌存储在数据库中。在代表用户直接上传视频之前,单独的脚本将检索该会话令牌。

这是我被绊倒的地方。当前用于上传视频的文档直接使用以下代码:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_AuthSub');

$yt = new Zend_Gdata_YouTube($httpClient);  

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 

$filesource = $yt->newMediaFileSource('somefile.mp4'); 
$filesource->setContentType('video/mp4'); 
$filesource->setSlug('somefile.mp4');  
$myVideoEntry->setMediaSource($filesource);  
$myVideoEntry->setVideoTitle('My Test Movie'); 
$myVideoEntry->setVideoDescription('My Test Movie'); 

$myVideoEntry->setVideoCategory('Entertainment');  
$myVideoEntry->SetVideoTags('test');  
$myVideoEntry->setVideoDeveloperTags(array('test', 'tester'));  

$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';  

$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');

我对如何正确制定以下部分的$ httpClient变量感到困惑:

$yt = new Zend_Gdata_YouTube($httpClient);

我已经将会话令牌存储在数据库中,并且需要跳过身份验证,而仅使用我的会话令牌执行直接上载。

任何帮助表示赞赏。

谢谢,
特根·斯奈德(Tegan Snyder)

参考方案

我能够找出解决方案。如果有人对这里感兴趣的就是我的代码。

<?php
$clientLibraryPath = '/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_YouTube'); 
Zend_Loader::loadClass('Zend_Uri_Http');

$sessionToken = '[whatever this is]';
$developerKey = '[whatever this is]';

$httpClient = new Zend_Gdata_HttpClient();
$httpClient->setAuthSubToken($sessionToken);

$yt = new Zend_Gdata_YouTube($httpClient, '23', '234', $developerKey);

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$file= '../path_to_file/filename.mp4';
$file = realpath($file);  

$filesource = $yt->newMediaFileSource($file); 
$filesource->setContentType('video/mp4'); 
$filesource->setSlug($file);  
$myVideoEntry->setMediaSource($filesource);  
$myVideoEntry->setVideoTitle('My Test Movie'); 
$myVideoEntry->setVideoDescription('My Test Movie'); 

$myVideoEntry->setVideoCategory('Entertainment');  
$myVideoEntry->SetVideoTags('testme');  
$myVideoEntry->setVideoDeveloperTags(array('tester', 'test'));  

$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';  


try {  

    $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry'); 

} catch (Zend_Gdata_App_HttpException $httpException) {   

    echo $httpException->getRawResponseBody();

} catch (Zend_Gdata_App_Exception $e) {

    echo $e->getMessage();

}

?>

PHP Zend Controller插件被调用两次 - php

我注意到我的插件被调用了两次。我知道这个事实是因为在我的ViewSetup插件中它注册了标题,并且标题两次包含相同的内容。有任何想法吗? 参考方案 您最有可能将呼叫复制到preDispatch或postDispatch。对于尚未调度的每个请求,在Zend_Controller_Front::dispatch的循环内调用这些方法。这意味着将分派设置为false…

Google Analytics PHP API(GAPI)-获取直接流量数据 - php

我是Google Analytics(分析)的新手,但仍能找到解决方法。我正在尝试找到一种方法来在仪表板上的直接流量(流量来源->来源->下)下检索数据(着陆页,访问次数,页面/访问次数,平均访问持续时间,新访问百分比,跳出率)直接)。我试过通过使用define('filter', 'source == direct…

PHP:不推荐使用password_hash的'salt'选项 - php

我正在使用密码哈希进行注册。我需要手动创建Salt,以下是我使用的代码:$options = [ 'cost' => 11, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ]; $password = password_hash( $this->…

Google Analytics PHP API:找不到目标 - php

在我公司,我们决定使用Google Analytics(分析)来获取有关访问者,进入渠道等的一些有趣指标...当访问者提交联系表单时,我创建了一个“触发”的目标,一切工作正常,我什至创建了一个细分来预览使用该表单的人与其他人之间的区别。使用PHP API,我有自己的仪表板表,其中逐个列出了每个会话的一些详细信息,其中包括:每个访问的URL约会时间如果来自Ad…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…