我正在使用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 我认为视频是“喜欢的”,但类似的计数器并没有增加。没人能看到这样的。谁能告诉我我做错了什么?这是限制吗?或者它是对Bots的预防?
答案 0 :(得分:0)
您是否尝试过实际获得视频评分? (https://developers.google.com/youtube/v3/docs/videos/getRating)。
在喜欢视频之前和之后获取视频的评级,然后您可以验证评分计数是否增加。可能存在图形延迟。
raw api call是: 获取https://www.googleapis.com/youtube/v3/videos/getRating?id=pwi9TAKUMYI&key= {YOUR_API_KEY}