1

我正在使用 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

我提示我必须将视频添加到“喜欢的”播放列表中,它会自动为该视频添加一个喜欢。

这是我如何获得喜欢的播放列表

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

如果我喜欢我自己上传的视频,它可以工作。但是,如果我尝试点赞另一个 youtuber 上传的视频,则会出现以下错误: http ://pokit.org/get/?d25a148b2a20d169488cf167d22ad7b0.jpg 我将视频视为“点赞”,但点赞计数器并未增加。没有其他人可以看到这样的。谁能告诉我我做错了什么?那是限制吗?或者它是针对机器人的预防措施?

4

1 回答 1

0

您是否尝试过实际获得视频的评分?(https://developers.google.com/youtube/v3/docs/videos/getRating)。

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

原始 API 调用是:GET https://www.googleapis.com/youtube/v3/videos/getRating?id=pwi9TAKUMYI&key= {YOUR_API_KEY}

于 2015-02-24T05:21:38.947 回答