Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:29:11+00:00 2026-05-27T21:29:11+00:00

I have a project for a client that will be using a YouTube comment

  • 0

I have a project for a client that will be using a YouTube comment stream as a type of “chat.” I am making an authenticated call to YouTube using the GData APIs with the Zend Framework. I am looking for a way to run the script that will pull the comment stream with a refresh button so that the users don’t have to refresh the page to see their comment, or any new comments that appear. I believe this can be accomplished with JQuery, but after a bt of searching I haven’t really found a good explanation as to how. Here are a few brief snippits of my code to give you some idea of what I am looking at:

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$_SESSION['yt'] = serialize($yt);

/***************** Adds a comment if applicable *****************/

if(isset($_POST['btn_submit']))
{
$videoEntry = $yt->getVideoEntry('QQoFLrZ5C3M');

$newComment = $yt->newCommentEntry();
$newComment->content = $yt->newContent()->setText($_POST['comment']);

// post the comment to the comments feed URL for the video
$commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl();
$updatedVideoEntry = $yt->insertEntry($newComment, $commentFeedPostUrl,
'Zend_Gdata_YouTube_CommentEntry');
}

                        /****************************************************************/


<div id="coments">

$commentFeed = $yt->getVideoCommentFeed('QQoFLrZ5C3M');

echo '<div id="refresh"><a href="#" style="margin-right: 15px; border: 0;"><img src="../common/img/refresh.png" alt="refresh" border="0" /></a></div>';

foreach ($commentFeed as $commentEntry) {
echo '<div class="comment">';
echo  '<a href="http://youtube.com/user/' . utf8_decode(utf8_encode($commentEntry->author[0]->name->text)) . '" target="_blank" class="youtube_user">' . utf8_decode(utf8_encode($commentEntry->author[0]->name->text)) . '</a><br />';

echo  '<span style="font-size: 14px;">' . utf8_decode(utf8_encode($commentEntry->content->text)) . '</span><br />';

// Format time
$timeAgoObject = new convertToAgo;
$ts = strtotime($commentEntry->updated->text);
$timestamp = ($timeAgoObject -> makeAgo($ts)); // Then convert to ago time

echo  '<div class="yt_timestamp">' . $timestamp  . '</div>';
echo '</div>';
}
?>
</div>

Note that the youtube class is not always new (hence the serialization into a session variable) I just stripped out the if statement for easy reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:29:12+00:00Added an answer on May 27, 2026 at 9:29 pm

    I created an example for you to use. It utilizes the Youtube JSON API somewhat detailed here: http://code.google.com/apis/youtube/2.0/reference.html#Comments_Feeds

    Insead of XML I am using JSON.

    To get the ‘data’ of your video with JSON, use http://gdata.youtube.com/feeds/api/videos/YOURVIDEOID/comments

    Example:
    http://jsfiddle.net/A32H2/2/

    //"The Dark Knight Rises trailer, sweded" comments
    //http://www.youtube.com/watch?v=KrmEyPkgDf8
    
        <div id="comments"></div>
    
        $.ajax({
            url: "http://gdata.youtube.com/feeds/api/videos/KrmEyPkgDf8/comments?v=2&alt=json&max-results=50",  
            //gets the max first 50 results.  To get the 'next' 50, use &start-index=50
            dataType: "jsonp",
            success: function(data){
                $.each(data.feed.entry, function(key, val) {
    
                    comment = $("<div class='comment'></div>");
    
                    author = $("<a target='_blank' class='youtube_user'></a>");
                    author.attr("href", "http://youtube.com/user/" + val.author[0].name.$t);
                    author.html(val.author[0].name.$t);
    
                    content = $("<div style='font-size: 14px;' class='content'></div>");
                    content.html(val.content.$t);
    
                    comment.append(author).append(content);
                    $('#comments').append(comment);
                });
            }
        });
    

    Also I would recommend changing the title of your question to something more descriptive, such as “Get Youtube comments with jQuery”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Flex client and a server that is using the Spring/Blazeds project.
We have a client that has Oracle Standard , and a project that would
I'm dipping my toes into Android development. I have a project that will interface
I have a client that wants to connect to his MySQL database using Dial-up/Modem
I am about to embark on a project mostly using C# that will involve
I have this method, that will be called against from a WCF Client, but
I have a client that I am doing a very small project for. His
I have a .NET 4.0 project with two modules that will communicate via WCF
I'm working on project that will work real time: I have to write a
Hope I'm asking this correctly: I have a project Projects.Client I have my class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.