如何使用YouTube Data API v3喜欢视频



我正在使用Java中的YouTube Data API V3,我正在尝试"喜欢"一个视频。我正在使用以下方法:

private static String insertPlaylistItem(String playlistId, String videoId) throws IOException {
        // Define a resourceId that identifies the video being added to the
        // playlist.
        ResourceId resourceId = new ResourceId();
        resourceId.setKind("youtube#video");
        resourceId.setVideoId(videoId);
        // Set fields included in the playlistItem resource's "snippet" part.
        PlaylistItemSnippet playlistItemSnippet = new PlaylistItemSnippet();
        playlistItemSnippet.setTitle("First video in the test playlist");
        playlistItemSnippet.setPlaylistId(playlistId);
        playlistItemSnippet.setResourceId(resourceId);
        // Create the playlistItem resource and set its snippet to the
        // object created above.
        PlaylistItem playlistItem = new PlaylistItem();
        playlistItem.setSnippet(playlistItemSnippet);
        // Call the API to add the playlist item to the specified playlist.
        // In the API call, the first argument identifies the resource parts
        // that the API response should contain, and the second argument is
        // the playlist item being inserted.
        YouTube.PlaylistItems.Insert playlistItemsInsertCommand =
                youtube.playlistItems().insert("snippet,contentDetails", playlistItem);
        PlaylistItem returnedPlaylistItem = playlistItemsInsertCommand.execute();

    System.out.println("New PlaylistItem name: " + returnedPlaylistItem.getSnippet().getTitle());
    System.out.println(" - Video id: " + returnedPlaylistItem.getSnippet().getResourceId().getVideoId());
    System.out.println(" - Posted: " + returnedPlaylistItem.getSnippet().getPublishedAt());
    System.out.println(" - Channel: " + returnedPlaylistItem.getSnippet().getChannelId());
    return returnedPlaylistItem.getId();
}

上面的方法来自这里的官方YouTube示例:https://developers.google.com/youtube/v3/docs/playlists/insert?hl=de#examples

我会提示我必须将视频添加到"点赞"播放列表中,该播放列表会自动为该视频添加点赞。

以下是我如何获得Likes 的播放列表

....
String likesPlaylistId = channelsList.get(0).getContentDetails().getRelatedPlaylists().getLikes();
insertPlaylistItem(likesPlaylistId, "pwi9TAKUMYI" );

如果我喜欢我自己上传的视频,它是有效的。但是,如果我试图喜欢另一个youtuber上传的视频,会出现以下错误:http://pokit.org/get/?d25a148b2a20d169488cf167d22ad7b0.jpg我认为视频是"点赞"的,但点赞计数器并没有增加。没有人能看到这样。有人能告诉我我做错了什么吗?这是限制吗?还是预防肉毒杆菌?

你真的试过获得视频的评分吗?(https://developers.google.com/youtube/v3/docs/videos/getRating)。

在点赞视频之前和之后获取视频的评分,然后您可以验证评分计数是否增加。可能存在图形延迟。

原始api调用是:得到https://www.googleapis.com/youtube/v3/videos/getRating?id=pwi9TAKUMYI&key={YOUR_API_key}

相关内容

  • 没有找到相关文章