user1271022
user1271022

Reputation: 51

Embed youtube comments and like

I was wondering if it's possible to embed youtube videos' comments and like button with the video? If there is such thing, how can I do that or where can I get more info? Thanks

Upvotes: 5

Views: 18712

Answers (5)

PromInc
PromInc

Reputation: 1233

Adding the live chat could be done using 2 iframes. One for the video stream and one for live chat. Google has the documentation here.

https://support.google.com/youtube/answer/2524549?hl=en#zippy=%2Cembed-live-chat

<!-- video -->
<iframe src="https://www.youtube.com/embed/<VIDEO-ID>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

<!-- live chat -->
<iframe src="https://www.youtube.com/live_chat?v=<VIDEO-ID>&embed_domain=www.example.com"></iframe>

The biggest trick is notice the embed_domain=www.example.com query parameter in the second iframe (for the Live Chat). This needs to be set to the domain name that the iframes are embedded into.

Upvotes: 0

PYK
PYK

Reputation: 4331

EDITED: On Feb,2016 YT has stopped the solution bellow from working :-( I'll keep it here just for reference

FOR THE COMMENTS:

As YT has deprecated the gdata for the comments url, you can scrape 'em also from here; its a workaround though :D

https://www.youtube.com/all_comments?v=cOIKAnF3mjs

...no authentication needed! :) and if you want to work the client side only (in this example by cross-domain), go through JS

<textarea style="width:100%;height:100%" id=cu></textarea>
<script>
var r='';
function c(d)
            {
            for(i=0;i<=d.query.count-1;i++)
               r=r+d.results[i];
            document.getElementById('cu').innerHTML=r;
            }
</script>
<script src="http://query.yahooapis.com/v1/public/yql?q=%20SELECT%20*%20FROM%20html%20WHERE%20url%3D%22https://www.youtube.com/all_comments?v=cOIKAnF3mjs%22&callback=c"></script>

Upvotes: 1

Patrick
Patrick

Reputation: 589

YouTube does not have any embed code that you can use to embed comments. So basically there are 2 options to embed comments -

1. Use the YouTube API to embed and post comments. This will need a good coding knowledge.

To get comments use this endpoint

GET https://www.googleapis.com/youtube/v3/commentThreads

To add comments use this endpoint

POST https://www.googleapis.com/youtube/v3/playlistItems

2. Or you can use a ready-made plugin that allows this functionality. Here is a small demo of the Youmax plugin that will list comments as well as allow you to add comments.

Upvotes: 2

Matias Molinas
Matias Molinas

Reputation: 2296

Here you can see an example of how to get and display the video comments

Getting Youtube Video Information using javascript/jquery

and in the Topic Explorer project you can see how to add a 'like' or add the video to your favorites:

https://code.google.com/p/yt-topic-explorer/source/browse/app/views/main.html

<button ng-click="addToList($event.target, 'likes', videoResult.id)">{{'LIKE'|i18n}}</button>
<button ng-click="addToList($event.target, 'favorites', videoResult.id)">{{'FAVORITE'|i18n}}</button>

and in:

https://code.google.com/p/yt-topic-explorer/source/browse/app/scripts/controllers/main.js

$scope.addToList = function(target, listName, videoId) {
    var listId = $rootScope.relatedPlaylists[listName];

    target.textContent = topicExplorerApp.filter.i18n('ADDING');
    target.disabled = true;

    youtube({
      method: 'POST',
      service: 'playlistItems',
      params: {
        part: 'snippet'
      },
      body: {
        snippet: {
          playlistId: listId,
          resourceId: {
            kind: constants.VIDEO_KIND,
            videoId: videoId
          }
        }
      },
      callback: function(results) {
        if ('error' in results) {
          target.textContent = 'Error';
        } else {
          target.textContent = topicExplorerApp.filter.i18n('ADDED');
        }
      }
    });
  };

Upvotes: 2

Uri Goren
Uri Goren

Reputation: 13700

You can Access YouTube Comments by processing this URL

http://gdata.youtube.com/feeds/api/videos/{$videoID}/comments

The YouTube like functionality requires the user to be logged-in to his/hers Google account

Upvotes: 0

Related Questions