Youtube API (PHP) - how to add (existing) video to existing playlist?

后端 未结 1 2032
不思量自难忘°
不思量自难忘° 2021-01-14 17:05

I am using Youtube API to upload some video, but I can\'t figure out how to add uploaded video to specific playlist. I have searched all over Google and I haven\'t found any

相关标签:
1条回答
  • 2021-01-14 17:46

    The code in the doc you linked to gives you a starting point:

    $postUrl = $playlistToAddTo->getPlaylistVideoFeedUrl();
    // video entry to be added
    $videoEntryToAdd = $yt->getVideoEntry('4XpnKHJAok8');
    
    // create a new Zend_Gdata_PlaylistListEntry, passing in the underling DOMElement of the VideoEntry
    $newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());
    
    // post
    try {
      $yt->insertEntry($newPlaylistListEntry, $postUrl);
    } catch (Zend_App_Exception $e) {
      echo $e->getMessage();
    }
    

    Instead of 4XpnKHJAok8 in that example, you'd want to pass in the id of the new video, i.e. the $idv value in your script.

    That code assumes that you have a $playlistToAddTo object already, but you probably will have a playlist ID instead. You can modify it to read

    $postUrl = sprintf('https://gdata.youtube.com/feeds/api/playlists/%s?v=2', $playlistId);
    

    where $playlistId is the ID of the playlist you want to add the video to.

    0 讨论(0)
提交回复
热议问题