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

发布于 2024-12-19 19:53:53 字数 278 浏览 2 评论 0原文

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

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

有没有一种完全不同的方法可以工作?

I would like to display a progress bar for direct youtube uploads using the gdata api. I have the uploads getting kicked off in by an ajax call to an uploader.php script, and when it completes, I update the status on the page the user sees. I would really like to set a timer to update a progress bar every 5 seconds or so, so the user doesn't get impatient and cancel a perfectly good upload in progress.

I've seen many posts with people trying to find a way to get progress info back from their uploads while in progress, with the YouTube API using direct uploads. I haven't seen any answers. This seems like something that should be supported in the API. Is there not way to do this?

Is there a completely different way, that would work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-12-26 19:53:53

您可以创建一个 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

You can create a php page and do a "browser based upload" using CURL. This means that you have control over the upload and you can create a progress bar.

Here is an example of how an upload might look like. The bottom part of this code is the interesting part. It makes an "browser based upload" using CURL and then returns the result;

// 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;

You can read more here https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文