使用WordPress将视频上传到YouTube [英] Uploading videos to YouTube using WordPress

查看:123
本文介绍了使用WordPress将视频上传到YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望网站访问者可以直接从WordPress网站前端将视频上传到我的YouTube频道.

I would like to allow my website visitors to upload video to my YouTube channel directly from my WordPress website front end.

我尝试使用PHP API,但无法完成任务,可能是因为我仍然是PHP Coding的初学者.但是,我听说可以通过几个步骤完成jQuery的工作,我确实检查了YouTube API的文档,但不知道该怎么做.

I've tried using the PHP API but I couldn't accomplish the task, maybe because I'm still a beginner in the PHP Coding. However I've heard that the task can be done with jQuery in a few steps, I did check the documentations of the YouTube API but couldn't realize how to do it.

一个问题的答案表明我可以使用jQuery的POST将视频上传到YouTube,这是否意味着我可以使用类似的内容:

This answer on a question shows that I can upload a video to YouTube using jQuery's POST, so does that mean I can use something like:

jQuery.ajax({
        type: "POST",
        url:"http://uploads.gdata.youtube.com/feeds/api/users/<youtube_username>/uploads",
        data:'URL-TO-VIDEO-FILE',
        success: ....

谢谢

推荐答案

我已经使用我在网上(http://i-x.it/REJ6EN)上找到的lib在wordpress网站上完成了此操作.稍微进行一下Google搜索,您应该可以将视频直接发送到youtube.

Ive done this for my wordpress site using a lib I found on the web (http://i-x.it/REJ6EN). With a little bit of googling, you should be able to send videos directly to youtube..

<?php
    $youtube_email = ""; // Change this to your youtube sign in email.
    $youtube_password = ""; // Change this to your youtube sign in password.
    // Developer key: Get your key here: http://code.google.com/apis/youtube/dashboard/.
    $key = ""; 

    $source = 'BarBeachTV'; // A short string that identifies your application for logging purposes.
    $postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=" . $source;
    $curl = curl_init( "https://www.google.com/youtube/accounts/ClientLogin" );
    curl_setopt( $curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded" );
    curl_setopt( $curl, CURLOPT_POST, 1 );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, $postdata );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 1 );
    $response = curl_exec( $curl );
    curl_close( $curl );

    list( $auth, $youtubeuser ) = explode( "\n", $response );
    list( $authlabel, $authvalue ) = array_map( "trim", explode( "=", $auth ) );
    list( $youtubeuserlabel, $youtubeuservalue ) = array_map( "trim", explode( "=", $youtubeuser ) );

    $youtube_video_title = $video_title; // This is the uploading video title.
    $youtube_video_description = $video_description; // This is the uploading video description.   
    $youtube_video_keywords = 'BarBeachTV'; // This is the uploading video keywords.
    $youtube_video_category = 'Entertainment'; // This is the uploading video category. There are only certain categories that are accepted. See below 
    /* 
     * Accepted Categories:
     * 
        Film
        Autos
        Music
        Animals
        Sports
        Travel
        Shortmov
        Games
        Videblog
        People
        Comedy
        Entertainment
        News
        Howto
        Education
        Tech
        Nonprofit
        Movies
        Movies_anime_action
        Movies_action_adventure
        Movies_classics
        Movies_comedy
        Movies_documentary
        Moves_drama
        Movies_family
        Movies_foreign
        Movies_horror
        Movies_sci_fi_fantasy
        Movies_thriller
        Movies_shorts
        Shows
        Trailers
     */

    $data = '<?xml version="1.0"?>
                <entry xmlns="http://www.w3.org/2005/Atom"
                  xmlns:media="http://search.yahoo.com/mrss/"
                  xmlns:yt="http://gdata.youtube.com/schemas/2007">
                  <media:group>
                    <media:title type="plain">' . stripslashes( $youtube_video_title ) . '</media:title>
                    <media:description type="plain">' . stripslashes( $youtube_video_description ) . '</media:description>
                    <media:category
                      scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
                    <media:keywords>'.$youtube_video_keywords.'</media:keywords>
                  </media:group>
                </entry>';

    $headers = array( "Authorization: GoogleLogin auth=".$authvalue,
                 "GData-Version: 2",
                 "X-GData-Key: key=".$key,
                 "Content-length: ".strlen( $data ),
                 "Content-Type: application/atom+xml; charset=UTF-8" );

$curl = curl_init( "http://gdata.youtube.com/action/GetUploadToken");
curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"] );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
curl_setopt( $curl, CURLOPT_REFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $curl, CURLOPT_HEADER, 0 );

$response = simplexml_load_string( curl_exec( $curl ) );
curl_close( $curl );
?>

这篇关于使用WordPress将视频上传到YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆