2011-10-02 124 views
1

我完全不熟悉php。我正在嘗試構建一個系統將視頻上傳到YouTube並保留其網址。另一個Flash應用程序稍後將它們結合起來我正在清理目標,以便我可以放心,圖書館可以執行這些任務。從php訪問YouTube服務

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 = '[email protected]', 
       $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 {主}().. \ testphp.php:0

2 0.0086 560192 require_once(「C:\瓦帕\ WWW \ zend \ library \ Zend \ Gdata \ YouTube.php').. \ testphp.php:7

+0

附加'使用error_reporting(E_ALL); ini_set('display_errors',1);''<?php'標籤後面,可能是你有一個錯誤,但是它被壓制了。另外,在你的set_include_path調用中,我認爲'''zend \ library''需要''C:/ wamp/www/zend/library' – drew010

+0

編輯後的代碼在後面給出。誤差是 調用棧 #\t \t時間內存\t \t功能位置 \t 0.0011 374264 \t {主}()\t .. \ testphp.php:0 \t 0.0045 559056 \t require_once(「C:\ wamp \ www \ zend \ library \ Zend \ Gdata \ YouTube.php')\t .. \ testphp.php:7 – shababhsiddique

回答

0

您的代碼對我來說工作得很好,我只需將包含路徑從\zend\library調整爲X:/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 = '[email protected]', 
       $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 
+0

我已經關注了你的文章和所有以前的文章。你會看到編輯的代碼嗎?並找出我是否錯過了什麼?我仍然有同樣的問題。順便說一下在Windows中完整的地址是C:/ wamp/library/zend/library還是C:\ wamp \ library \ zend \ library? – shababhsiddique

0

取代

require_once 'Zend\Loader.php'; 

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

不工作,我也嘗試了通過改變require_once'..'的方法來解決同樣的問題 – shababhsiddique