insert video into a playlist with youtube api v3

后端 未结 3 1463
天涯浪人
天涯浪人 2020-12-31 12:52

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

相关标签:
3条回答
  • 2020-12-31 12:57

    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

    0 讨论(0)
  • 2020-12-31 13:05

    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.

    0 讨论(0)
  • 2020-12-31 13:12

    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()
    
    0 讨论(0)
提交回复
热议问题