1

I am using the YouTube Data API V3 in Java and I am trying to "like" a video. I am using the following method:

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();

}

The Method above came from the official YouTube Example located here: https://developers.google.com/youtube/v3/docs/playlists/insert?hl=de#examples

I go the hint that I have to add the video to the "liked" playlist, which automatically adds a like to that video.

Here is how I get the Playlist for Likes

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

If I like a video that I uploaded myself, it works. But If I try to like a video that another youtuber uploaded, the following error appears: http://pokit.org/get/?d25a148b2a20d169488cf167d22ad7b0.jpg I see the video as "liked" but the like counter isn't increasing. Noone else can see that like. Can anyone tell me what I am doing wrong? Is that a restriction? Or is it a prevention against Bots?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Dominik
  • 1,016
  • 11
  • 30

1 Answers1

0

Have you tried actually getting the rating of a video? (https://developers.google.com/youtube/v3/docs/videos/getRating).

Get the rating of the video before and after liking the video and then you can verify if the rating count increased. There might be a graphical delay.

raw api call is : GET https://www.googleapis.com/youtube/v3/videos/getRating?id=pwi9TAKUMYI&key={YOUR_API_KEY}

Rohan
  • 1,312
  • 3
  • 17
  • 43
  • Yep that returns true. So the liking works, but even after 14 days the likes are not visible to anyone. I liked my video with 4 different accounts, and only my own like got counted... – Dominik Feb 28 '15 at 12:20
  • @Dominik, have you found any solution to this? – Shajeel Afzal Jul 10 '20 at 19:43