KB.
KB.

Reputation: 3657

Deleting a video using YouTube API v3 PHP

I have the following code to delete a YouTube video using cURL. I'm getting a 401 response/authorization error. I've put in the API key in the url and do I put the access token in the bearer value in CURLOPT_HTTPHEADER area?

$url = "https://www.googleapis.com/youtube/v3/videos?id=VIDEO_ID_HERE&key=KEY_HERE";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/json','Authorization : Bearer '.$_SESSION['access_token']));
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

Are there any other mistakes I'm making?

Upvotes: 0

Views: 1070

Answers (1)

KB.
KB.

Reputation: 3657

Okay I had another question on the same topic (deleting videos) so I'll post that answer here now that I've figured it out in case someone finds this via Google. I never figured out the cURL method but the method using the google PHP library for v3 of their API is as follows:

$youtube = new Google_Service_YouTube($client);
...
//do your authoraisation stuff + getting access token etc
...
$youtube->videos->delete('<Your Video ID>');

Hope that helps!

Upvotes: 1

Related Questions