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 using php to do all of this but in order to make sure I have the correct idea of how each request/response works I attempted it in the browser with the API explorer
Now I am trying to insert videos into a playlist I just created (also through the API) but I am having some trouble figuring out exactly how my request is not properly formed
Here's The request
POST https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.1.AADtN_WT2TRZzH1t86nVlX26z9WPp-gnDTxVHGvdQ6xx0vyTzmkYeXkLdJerwllLzF_a
X-JavaScript-User-Agent: Google APIs Explorer
{
"snippet": {
"playlistId": "PL8hD12HFC-nuswc21_e64aPAy9B25sEH7",
"resourceId": {
"videoId": "KMGuyGY5gvY"
}
}
}
here is the response
400 Bad Request
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "invalidResourceType",
"message": "Resource type not supported."
}
],
"code": 400,
"message": "Resource type not supported."
}
}
the playlist is an empty publicly viewable playlist I created using the API Explorer and is viewable through standard youtube website. The video is randomly selected off of youtube ... tried a few as thought it might be a specific problem with a video but no luck .. I have switched on OAuth and am using an account that is a verified youtube partner
However I can seemed to figure out why the resource type is not supported I've looked around the web along with answers to the left without finding exactly what I am doing wrong.. any help with this problem would be greatly appreciated as I am kind of stuck at the moment
What should I do? You can continue using the v2 API for comments and uploading video captions for now, and we'll be adding this functionality into the v3 API soon. While we don't have specific dates yet, we will release that functionality so that developers have as much time as possible to migrate to v3.
Yes, using the YouTube API does not incur any monetary cost for the entity calling the API. If you go over your quota an 403 Error will be returned by the API.
Using the API, you can load or cue videos into a player view embedded in your application's UI. You can then control playback programmatically. For example, you can play, pause, or seek to a specific point in the currently loaded video.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With