2011-12-06 2 views
3

gdata API를 사용하여 YouTube에 직접 업로드 할 수있는 진행률 표시 줄을 표시하고 싶습니다. uploader.php 스크립트에 대한 ajax 호출로 업로드가 시작되고, 완료되면 사용자가 보는 페이지의 상태가 업데이트됩니다. 5 초마다 진행률 표시 줄을 업데이트하는 타이머를 설정하여 사용자가 참을성이 없어지고 진행중인 완벽하게 좋은 업로드를 취소하지 않도록하고 싶습니다.데이터가있는 YouTube 직접 업로드 진행률 표시 줄?

직접 업로드를 사용하는 YouTube API를 사용하여 진행중인 진행률 정보를 진행하는 방법을 찾기 위해 많은 게시물을 보았습니다. 나는 어떤 대답도 보지 못했다. 이것은 API에서 지원되어야하는 것으로 보입니다. 이것을 할 방법이 없습니까?

완전히 다른 방법이 있나요?

답변

0

PHP 페이지를 만들고 CURL을 사용하여 "브라우저 기반 업로드"를 할 수 있습니다. 즉, 업로드를 제어 할 수 있으며 진행률 표시 줄을 만들 수 있습니다.
업로드 방법은 다음과 같습니다. 이 코드의 맨 아래 부분이 흥미로운 부분입니다. CURL을 사용하여 "브라우저 기반 업로드"를 만든 다음 결과를 반환합니다.

// upload.php 


require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path 
Zend_Loader::loadClass('Zend_Gdata_YouTube'); 
$yt = new Zend_Gdata_YouTube(); 

// Define the authentication that will be used 
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

// Authenticate 
$authenticationURL= 'https://www.google.com/accounts/ClientLogin'; 
$httpClient = 
    Zend_Gdata_ClientLogin::getHttpClient(
       $username = "USERNAME", 
       $password = "PASSWORD", 
       $service = 'youtube', 
       $client = null, 
       $source = 'HTML SOURCE CODE SNIPPET', 
       $loginToken = null, 
       $loginCaptcha = null, 
       $authenticationURL); 

$applicationId = 'YOUR APPLICATION ID'; 
$clientId = 'Upload videos to youtube using the youtube API'; 
$developerKey = 'YOUR DEVELOPER KEY'; 
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); 



// create a new VideoEntry object 
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 

$myVideoEntry->setVideoTitle($videoTitle); 
$myVideoEntry->setVideoDescription($VideoDescription); 
// The category must be a valid YouTube category! 
$myVideoEntry->setVideoCategory($VideoCategory); 

// Set keywords. Please note that this must be a comma-separated string 
// and that individual keywords cannot contain whitespace 
$myVideoEntry->SetVideoTags($VideoTags); 

$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken'; 
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl); 
$tokenValue = $tokenArray['token']; 
$postUrl = $tokenArray['url']; 


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $postUrl."?nexturl=http://YOUR_WEBPAGE.com/"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
curl_setopt($ch, CURLOPT_POST, true); 
// same as <input type="file" name="file"> 
$post = array("file"=>"@".$VideoFile['tmp_name'], "token"=>$tokenValue); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch); 
$info = curl_getinfo($ch); 

echo $info; 

당신은 읽을 수 있습니다 여기 https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload

+1

당신이 국지적 브라우저 업로드 방법은이 문제를 피하기 위해해서 존재 (첫번째 YouTube에서 서버와 2 시간에) 두 번 동영상을 업로드해야하기 때문에 짜증이 더. – themihai