Javascript YouTube直接上传数据的进度条?

Javascript YouTube直接上传数据的进度条?,javascript,progress-bar,youtube-api,gdata,Javascript,Progress Bar,Youtube Api,Gdata,我想使用gdataapi显示一个用于直接上传youtube的进度条。我通过对uploader.php脚本的ajax调用启动了上传,当它完成时,我更新用户看到的页面上的状态。我真的很想设置一个计时器,每5秒左右更新一次进度条,这样用户就不会不耐烦,就可以取消正在进行的完美上传 我看过很多帖子,人们试图找到一种方法,在上传过程中通过YouTube API直接上传,从上传中获取进度信息。我没有看到任何答案。这似乎应该在API中得到支持。难道没有办法做到这一点吗 是否有一种完全不同的方式可以工作?您可以

我想使用gdataapi显示一个用于直接上传youtube的进度条。我通过对uploader.php脚本的ajax调用启动了上传,当它完成时,我更新用户看到的页面上的状态。我真的很想设置一个计时器,每5秒左右更新一次进度条,这样用户就不会不耐烦,就可以取消正在进行的完美上传

我看过很多帖子,人们试图找到一种方法,在上传过程中通过YouTube API直接上传,从上传中获取进度信息。我没有看到任何答案。这似乎应该在API中得到支持。难道没有办法做到这一点吗


是否有一种完全不同的方式可以工作?

您可以创建一个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;
//upload.php
需要_once'Zend/Loader.php';//Zend目录必须位于您的include\u路径中
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt=新的Zend_Gdata_YouTube();
//定义将要使用的身份验证
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
//鉴定
$authenticationURL='1!'https://www.google.com/accounts/ClientLogin';
$httpClient=
Zend_Gdata_客户端登录::getHttpClient(
$username=“username”,
$password=“password”,
$service='youtube',
$client=null,
$source='HTML源代码片段',
$loginToken=null,
$loginCaptcha=null,
$authenticationURL);
$applicationId='您的应用程序ID';
$clientId='使用youtube API将视频上载到youtube';
$developerKey='YOUR DEVELOPER KEY';
$yt=新Zend_Gdata_YouTube($httpClient、$applicationId、$clientId、$developerKey);
//创建新的VideoEntry对象
$myVideoEntry=new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($videoTitle);
$myVideoEntry->setVideoDescription($VideoDescription);
//该类别必须是有效的YouTube类别!
$myVideoEntry->setVideoCategory($VideoCategory);
//设置关键字。请注意,这必须是逗号分隔的字符串
//而且单个关键字不能包含空格
$myVideoEntry->SetVideoTags($VideoTags);
$tokenHandlerUrl=http://gdata.youtube.com/action/GetUploadToken';
$tokenArray=$yt->getFormUploadToken($myVideoEntry,$tokenHandlerUrl);
$tokenValue=$tokenArray['token'];
$postrl=$tokenArray['url'];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$postrl.“?下一步=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);
//同
$post=数组(“文件”=>“@”。$VideoFile['tmp_name'],“令牌”=>$tokenValue);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$response=curl\u exec($ch);
$info=curl\u getinfo($ch);
echo$info;

您可以在此处阅读更多内容

,这很糟糕,因为您必须上载两次视频(第一次在服务器上,第二次在youtube上)。浏览器上载方法的存在正是为了避免这种情况。