从php访问youtube服务

时间:2011-10-02 19:29:32

标签: php zend-framework youtube

我是php的新手。我正在尝试构建一个系统,将视频上传到youtube并保留其网址。另一个Flash应用程序稍后将它们组我正在清理目标,以便我可以确信库可以执行这些任务。

1)在默认频道上传 2)获取视频网址 3)下载视频以供离线观看

我找到了通过谷歌搜索与php一起使用的zend库。但面临很多问题。我正在使用WAMP。我将zend库文件夹复制到“C:\ wamp \ www \ zend”并在此处更改了php.ini

Windows:“\ path1; \ path2” include_path =“.; C:\ wamp \ www \ zend \ library; c:\ php \ includes”

感觉没有变化。所以我试图用这段代码测试库。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

set_include_path('C:/wamp/library/zend/library' . PATH_SEPARATOR . get_include_path());

require_once 'zend/library/Zend/Gdata/YouTube.php';
require_once 'zend/library/Zend/Gdata/ClientLogin.php';

require_once 'zend/library/Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = 
  Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'shabab.h.siddique@gmail.com',
              $password = '***',
              $service = 'youtube',
              $client = null,
              $source = 'testphp', 
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);



$developerKey = 'AI3....w';
$applicationId = 'Student Collaborative Video System';
$clientId = 'Student Collaborative Video System';

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

$yt->setMajorProtocolVersion(2);


$videoFeed = $yt->getVideoFeed(Zend_Gdata_YouTube::VIDEO_URI);
printVideoFeed($videoFeed);

var_dump($videoFeed);

?>

我目前看到的错误是

1 0.0023 375392 {main}().. \ testphp.php:0

2 0.0086 560192 require_once('C:\ wamp \ www \ zend \ library \ Zend \ Gdata \ YouTube.php').. \ testphp.php:7

2 个答案:

答案 0 :(得分:0)

您的代码对我来说很好,我只需要调整从\zend\libraryX:/zend/framework/library的包含路径,这是我把它放在我的电脑上的地方。设置包含路径时,请确保使用框架的完整路径。

然后我需要专门包含我们将要使用的Zend_Gdata文件。这是有效的代码。

<?php 
set_include_path('X:/zend/framework/library' . PATH_SEPARATOR . get_include_path());

// we must manually require these since we didn't set up the autoloader
require_once 'Zend/Gdata/YouTube.php';
require_once 'Zend/Gdata/ClientLogin.php';

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = 
  Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'me@myemail.com',
              $password = 'mypass',
              $service = 'youtube',
              $client = null,
              $source = 'MySource', // a short string identifying your application
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);

$developerKey = 'myprodkey';
$applicationId = 'TestProduct';
$clientId = 'Student Collaborative Video System';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$yt->setMajorProtocolVersion(2);
$videoFeed = $yt->getVideoFeed(Zend_Gdata_YouTube::VIDEO_URI);
//printVideoFeed($videoFeed);

var_dump($videoFeed);  // worked, printed out a list of videos in my app

答案 1 :(得分:0)

替换

require_once 'Zend\Loader.php';

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();