Reputation: 810
I'm trying to delete a video from a Youtube playlist but the server keeps responding with this:
<errors xmlns='http://schemas.google.com/g/2005'>
<error>
<domain>GData</domain>
<code>ServiceForbiddenException</code>
<internalReason>User authentication required.</internalReason>
</error>
</errors>
The weird thing is i can delete playlists and and add videos to playlists. I'm following Google's documentation found here:
I'm using a request shaped like this:
URL
DELETE https://gdata.youtube.com/feeds/api/playlists/PLAYLIST_ID/VIDEO_ID
DELETE https://gdata.youtube.com/feeds/api/playlists/PLZsHJpFf2dLtEhsYEISc2FR2JWYeIC8KZ/IcxQznDe4u8
Headers: (i use the exact same headers for ALL requests)
Authorization: Bearer ************************
Content-Type: application/atom+xml
Host: gdata.youtube.com
X-GData-Key: key=***************************
gdata-version: 2
Another odd thing is when i type in the request url in the adress it says "Playlist video not found" I've supplied the Youtube video id. Mebbe it's not that id i need to supply. I tried with playlist index, i.e just a number. No luck. halp!
Upvotes: 3
Views: 822
Reputation: 810
Allow me to answer my own question.
In the documentation linked they've stated that you need a PLAYLIST_ENTRY_ID which is not the same id that's written in the address on Youtube. This id comes from the entries that you request via their feed request. Every entry (every video) has a property named id (it's in feed -> entry -> id[text]) which contains something like this:
tag:youtube.com,2008:playlist:PLZsHJpFf2dLs_n7e69v5SUNQRuZTMnLcM:PLhRVbNPJX-c0PUOsjeulCsgAx-ydeUUdJhpxbacX0VFk
Which in this case can be understood as
bla:bla:bla:PLAYLIST_ID:PLAYLIST_ENTRY_ID
so the id i was looking after was the rest of the string after the last colon. In Javascript i fetched it like this: (I'm using an xml to json parser, but it's the .split(":").pop() that will give you the desired id)
var deleteId=json.feed.entry[i]["id"]["#text"].split(":").pop();
In this case the id resulting id would be: PLhRVbNPJX-c0PUOsjeulCsgAx-ydeUUdJhpxbacX0VFk.
So the final request url for the video of ytId IcxQznDe4u8 is not
https://gdata.youtube.com/feeds/api/playlists/PLZsHJpFf2dLtEhsYEISc2FR2JWYeIC8KZ/IcxQznDe4u8
but instead
https://gdata.youtube.com/feeds/api/playlists/PLZsHJpFf2dLtEhsYEISc2FR2JWYeIC8KZ/PLhRVbNPJX-c0PUOsjeulCsgAx-ydeUUdJhpxbacX0VFk
*flies away*
Upvotes: 3