【问题标题】:Accessing youtube services from php从 php 访问 youtube 服务
【发布时间】:2011-10-02 19:29:31
【问题描述】:

我对 php 完全陌生。我正在尝试构建一个系统来将视频上传到 youtube 并保留他们的 URL。另一个 Flash 应用程序稍后将它们组合在一起。我正在清除目标,以便我可以确信图书馆可以执行这些任务。

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

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

;窗口:“\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

【问题讨论】:

  • &lt;?php标签后添加error_reporting(E_ALL); ini_set('display_errors', 1);,可能是你有错误但它被抑制了。另外,在您的 set_include_path 调用中,我认为 \zend\library 需要是 C:/wamp/www/zend/library
  • 编辑后的代码在上面的帖子中给出。错误是 Call Stack # Time Memory Function Location 1 0.0011 374264 {main}( ) ..\testphp.php:0 2 0.0045 559056 require_once( 'C:\wamp\www\zend\library\Zend\Gdata\YouTube.php ' ) ..\testphp.php:7

标签: php zend-framework youtube


【解决方案1】:

您的代码对我来说运行良好,我只需将包含路径从 \zend\library 调整为 X:/zend/framework/library,这是我将它放在我的 PC 上的位置。确保在设置包含路径时使用框架的完整路径。

然后我需要特别包含我们将使用的 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

【讨论】:

  • 我已经关注了你的帖子和之前的所有帖子。你会看到编辑后的代码吗?看看我是否遗漏了什么?我仍然有同样的问题。顺便说一句,完整的地址是 C:/wamp/library/zend/library 还是 windows 中的 C:\wamp\library\zend\library?
【解决方案2】:

替换

require_once 'Zend\Loader.php';

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

【讨论】:

  • 不工作,我也试过你的方法,通过改变 require_once '..' 仍然是同样的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
  • 2019-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-25
相关资源
最近更新 更多