【问题标题】:using php, how do i upload youtube videos on my site using the youtube v3 api?使用 php,我如何使用 youtube v3 api 在我的网站上上传 youtube 视频?
【发布时间】:2017-10-27 10:50:17
【问题描述】:

我正在做这个网站,用户在其中注册并使用 youtube 链接上传视频。 我不想使用 Youtube 频道。 我是 php 编程的新手,我不知道如何去做。 用户上传视频后,该页面还必须有网站上的视频类别列表。

任何帮助将不胜感激

编辑:这是我到目前为止得到的,我不知道我是怎么到这里的,我只知道它不起作用。 它有一个模式,允许用户输入视频链接并将其导入到将显示所有视频的页面。

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test 1</title>
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="assets/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/style.css">
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    </head>
<body>
<div class="col-md-8">
<div class="video-embed-iframe">
<div class="embed-responsive embed-responsive-16by9">
<iframe src="http://www.youtube.com/embed/{$videos_youtube_id}?autoplay={$player_autoplay}&showinfo={$player_showinfo}&rel={$player_related}&controls={$player_controls}&loop={$player_loop}&color={$player_color}" allowfullscreen></iframe>
</div>
</div>



<div class="modal fade" id="upload-modal">
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title"><span class="fa fa-upload"></span> {$lang_upload_new_videos}</h4>
    </div>
    <div class="modal-body">
        <div id="upload-message"></div>
        <form id="upload-form" method="POST" action="">
        <div class="row">
          <div class="col-md-12">
          <div class="form-group">              
            <label for="category">{$lang_category} <span>*</span> </label>
            <select class="form-control" name="category" id="category">
                {section name=x loop=$categories}
                    <option value="{$categories[x].id}">{$categories[x].category}</option>
                {/section}
            </select>
          </div>
          <div class="form-group">
            <label for="link">{$lang_videos_link} <span>*</span> </label>
            <input type="text" class="form-control" name="link" dir="ltr" id="link" placeholder="https://www.youtube.com/watch?v=uJcB3ZaaLlA" />
            <p class="help-block" dir="ltr">youtube video link</p>
          </div>

          </div>
        </div>
        <div class="modal-footer">
            <button type="button" id="import_btn" class="btn btn-inverse pull-left">{$lang_import}</button>
        </div>
        </form>
</div>
</div>
</div>

</body>
</html>

【问题讨论】:

  • 在发布问题之前,您应该进行适当的研究并尝试自己解决问题。然后,如果您遇到特定的问题,请回来向我们展示您的尝试。请阅读How much research effort is expected of Stack Overflow users?How to create a Minimal, Complete, and Verifiable exampleHow do I ask a good question?
  • 我查看了 youtube 文档,这是第一。第二是php文档都让我更加困惑。这就是我问这个问题的原因。阅读问题“我是 PHP 编程新手”。我什至尝试这样做,但我的解决方案很弱,根本不起作用。就像我说的,我对 php 很陌生,第一周就开始了。与其那样把我击倒,你为什么不带着更积极的东西回来。我一直在做适当的研究,但仍然坚持,因此我问,我不会问我是否知道这会是一个人会得到的回应。
  • 您应该始终在原始帖子中包含您所做的一切。否则,我们不知道您读过什么或尝试过什么。我们很乐意提供帮助,但我们确实需要知道您做了什么(或是否)做了任何尝试。 SO 有关于编写问题的指南。我确实在我的原始评论中包含了其中几个的链接。这不是出于恶意,而是为了让您知道为什么缺少这个问题以及如何改进它。

标签: php youtube-api youtube-data-api


【解决方案1】:

既然您说您也是 PHP 新手,我建议您在这件事上再深入一点。

但这是一个有效的代码,希望对您有所帮助。

if($client->getAccessToken()) {
$snippet = new Google_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test descrition");
$snippet->setTags(array("tag1","tag2"));
$snippet->setCategoryId("22");

$status = new Google_VideoStatus();
$status->privacyStatus = "private";

$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);

$error = true;
$i = 0;

try {
    $obj = $youTubeService->videos->insert("status,snippet", $video,
                                     array("data"=>file_get_contents("video.mp4"), 
                                    "mimeType" => "video/mp4"));
} catch(Google_ServiceException $e) {
    print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage(). " <br>";
    print "Stack trace is ".$e->getTraceAsString();
}

}

【讨论】:

  • 谢谢。你不知道我的压力有多大。我完全被困住了。起初我有一个视频和一个弹出模式,但它们都不起作用,我一直看到相同的代码并潜入文档。我迷失了更多。
  • 是的,我明白了很多。有时,最好收工,明天重新开始。
猜你喜欢
  • 2012-12-23
  • 2014-02-20
  • 2014-12-30
  • 1970-01-01
  • 2012-10-27
  • 1970-01-01
  • 1970-01-01
  • 2015-09-20
  • 2013-01-18
相关资源
最近更新 更多