1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

YT mini add commenter script

Discussion in 'PHP & Perl' started by Mutikasa, Apr 16, 2012.

  1. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    575
    Likes Received:
    212
    This script adds comment on YT video.
    Input username, password, videoId and comment.
    Do not refresh after you submit, it will submit again.
    To have it work you have to get Zend_Gdata library and get your own developer key.

    I'm putting code here for the marketers from YT section.
    For the PHP coders, I assume you know more so I'm not explaining much.


    PHP:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <title>untitled</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <meta name="generator" content="Geany 0.19.1" />
    </head>

    <body>
    <?php

    // form for input
    if(!isset($_POST['username'])) {
      echo 
    "<form method=post action=>";
        echo 
    "username: <input type=text name=username><br>";
        echo 
    "pass: <input type=text name=password><br>";
        echo 
    "videoId: <input type=text name=videoid><br>";
        echo 
    "comment: <textarea name=comment></textarea>";
        echo 
    "<input type=submit name=submit>";    
        echo 
    "</form>";
    }

    //after form submit load libraries
    if (isset($_POST['username'])) {
        require_once(
    'Zend/Loader.php');
      
    Zend_Loader::loadClass('Zend_Gdata_YouTube');
      
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

    //authenticate user
      
    $authenticationURL'https://www.google.com/accounts/ClientLogin';
      
    $httpClient 
      
    Zend_Gdata_ClientLogin::getHttpClient(
                  
    $username $_POST['username'],
                  
    $password $_POST['password'],
                  
    $service 'youtube',
                  
    $client null,
                  
    $source ''// a short string identifying your application
                  
    $loginToken null,
                  
    $loginCaptcha null,
                  
    $authenticationURL);

      
    $devkey 'get_your_key'
      
    $yt = new Zend_Gdata_YouTube($httpClient,'',null,$devkey);
      
    $yt->setMajorProtocolVersion(2);
      
      
    //get video entry from video ID and insert comment
      
    $videoEntry $yt->getVideoEntry($_POST['videoid']);
      
    $newComment $yt->newCommentEntry();
      
    $newComment->content $yt->newContent()->setText($_POST['comment']);
      
    $commentFeedPostUrl $videoEntry->getVideoCommentFeedUrl();
      
    $updatedVideoEntry $yt->insertEntry($newComment$commentFeedPostUrl,'Zend_Gdata_YouTube_CommentEntry');
      
      echo 
    "Done! <a href=http://www.youtube.com/watch?v=".$_POST['videoid'].">video link</a>";
    }
    ?> 
    </body>

    </html>