Embed youtube comments and like

馋奶兔 提交于 2019-11-27 02:58:49

问题


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


回答1:


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



回答2:


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.




回答3:


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>



回答4:


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



来源:https://stackoverflow.com/questions/9716005/embed-youtube-comments-and-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!