Hey so I am fairly familiar to the youtube api .. I know how to read channels and playlist along with getting any relevant video information I identify as Important I\'m us
Read documentation at Youtube Data Api
$playlistId = 'REPLACE_WITH_YOUR_PLAYLIST_ID_STARTS_WITH_PL';
$resourceId = new Google_Service_YouTube_ResourceId();
$resourceId->setVideoId('REPLACE_WITH_VIDEO_ID_YOU_WANT_TO_ADD');
$resourceId->setKind('youtube#video');
$playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet();
$playlistItemSnippet->setTitle('YOUR_VIDEO_TITLE');
$playlistItemSnippet->setPlaylistId($playlistId);
$playlistItemSnippet->setResourceId($resourceId);
$playlistItem = new Google_Service_YouTube_PlaylistItem();
$playlistItem->setSnippet($playlistItemSnippet);
$playlistItemResponse = $youtube->playlistItems->insert(
'snippet,contentDetails', $playlistItem, array());</i>
Full project is available at my GitHub
Your resourceId
isn't complete, as it doesn't identify to the API how to interpret the videoId
parameter. Try setting the kind
attribute of the resourceId
, like this:
"snippet": {
"playlistId": "PL8hD12HFC-nuswc21_e64aPAy9B25sEH7",
"resourceId": {
"kind": "youtube#video",
"videoId": "KMGuyGY5gvY"
}
}
That way, the API will know in which 'domain' (so to speak) to locate the resource identified by the string you send in.
this will help constructing resourceID
def add_video_to_playlist(videoID,playlistID):
youtube = get_authenticated_service() #write it yourself
add_video_request=youtube.playlistItems().insert(
part="snippet",
body={
'snippet': {
'playlistId': playlistID,
'resourceId': {
'kind': 'youtube#video',
'videoId': videoID
}
#'position': 0
}
}
).execute()