douban5644 2017-10-27 10:50
浏览 70
已采纳

使用php,如何使用youtube v3 api在我的网站上传YouTube视频?

I am doing this website where the user registers and uploads a video using youtube link. I don't want to use a Youtube Channel. I am new to programming in php and i have no idea as to how to go about this. The page also has to have a category list of the videos on the website after the user uploads a video.

Any help would be appreciated

edit: here is what i got so far, i don't know how i got here, all i know is that it doesn't work. It has a modal which lets the user input the video link and import it to a page that will display all videos.

<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>
  • 写回答

1条回答 默认 最新

  • dqwyghl0649 2017-10-27 11:56
    关注

    Since you said you are new to PHP as well I suggest you dig in a bit more on the matter.

    But this is a working code, that hopefully help you a bit.

    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();
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计