{"id":2834,"date":"2017-07-07T04:31:05","date_gmt":"2017-07-07T04:31:05","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2834"},"modified":"2017-07-07T04:31:05","modified_gmt":"2017-07-07T04:31:05","slug":"14-youtube-data-api-captions-delete-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/07\/07\/14-youtube-data-api-captions-delete-function\/","title":{"rendered":"14 &#8211; YouTube Data API &#8211; Captions &#8211; delete function"},"content":{"rendered":"            <script type=\"text\/javascript\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushPhp.js\"><\/script>\n<p style=\"text-align: center;\"><strong>This is article 14 of the YouTube API With PHP series.<\/strong><\/p>\n<p class=\"NormalTextDroid\">The delete call deletes a specified Caption track.<\/p>\n<p class=\"NormalTextDroid\">\u00a0The Request URL is<\/p>\n<pre class=\"PHPCode\"><span style=\"color: #999999;\">\u00a0DELETE https:\/\/www.googleapis.com\/youtube\/v3\/captions\/<\/span><\/pre>\n<p><strong>Parameters<br \/>\n<\/strong><\/p>\n<ul>\n<li><strong>key<\/strong> (string) required. Your API key<\/li>\n<li><strong>id<\/strong> (string) required This is added as a suffix to the GET url. This has to be a valid id for an existing Caption track.<\/li>\n<li><strong>onBehalfOfContentOwner<\/strong> (string) optional. This is relevant only for YouTube Channel Partners. For this parameter, the API request URL should have user authentication.We will not be exploring this option.<\/li>\n<\/ul>\n<p><strong>Response<\/strong><\/p>\n<p>On a successful call, no content is returned &#8211; only HTTP status code 204 is returned.<\/p>\n<p>This call requires user-authentication so you can only delete Caption tracks of your own videos. You need a valid Caption Track id. You can get a list of all the Caption tracks of a video by running the list call.<\/p>\n<p>Here is sample code which deletes a Caption track:<\/p>\n<p><pre class=\"brush: php\">&lt;?php\r\n    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);\r\n    set_time_limit(60 * 3);\r\n    session_start();\r\n\r\n    $clientId = &quot;***&quot;;\r\n    $clientSecret = &quot;***&quot;;\r\n    $g_youtubeDataAPIKey = &quot;***&quot;;\r\n\r\n    $captionId =  &quot;axgUe6Et_P4isLwoI955G63ZxOiToJxi1IhwL_W9S9w61KPnmOvuOiUevcv8buAmn8R8Y0fmRm8=&quot;;\r\n    \r\n    $_SESSION[&quot;code_id&quot;] = $_SERVER[&quot;PHP_SELF&quot;];\r\n\r\n    if ($_SESSION[&quot;access_token&quot;] == null || $_SESSION[&quot;access_token&quot;] == &quot;&quot;) {\r\n   \t \/\/ check for oauth response\r\n   \t header(&quot;Location: ..\/..\/init-login.php&quot;);\r\n   \t exit;\r\n    }\r\n\r\n   \t $accessToken = $_SESSION[&quot;access_token&quot;];\r\n   \t \r\n   \t \/\/ make api request\r\n   \t $url = &quot;https:\/\/www.googleapis.com\/youtube\/v3\/captions\/?id=&quot; . $captionId . &quot;&amp;key=&quot; .\r\n   \t\t\t $g_youtubeDataAPIKey . &quot;&amp;access_token=&quot; . $accessToken;\r\n   \t $curl = curl_init();\r\n   \t curl_setopt_array($curl, array(\r\n   \t\t\t\t CURLOPT_RETURNTRANSFER =&gt; 1,\r\n   \t\t\t\t CURLOPT_URL =&gt; $url,\r\n   \t\t\t\t CURLOPT_USERAGENT =&gt; &#039;YouTube API Tester&#039;,\r\n   \t\t\t\t CURLOPT_SSL_VERIFYPEER =&gt; 1,\r\n   \t\t\t\t CURLOPT_SSL_VERIFYHOST=&gt; 0,\r\n   \t\t\t\t CURLOPT_HEADER=&gt;1,\r\n   \t\t\t\t CURLOPT_CAINFO =&gt; &quot;..\/..\/cert\/cacert.pem&quot;,\r\n   \t\t\t\t CURLOPT_CAPATH =&gt; &quot;..\/..\/cert\/cacert.pem&quot;,\r\n   \t\t\t\t CURLOPT_FOLLOWLOCATION =&gt; TRUE,\r\n   \t\t\t\t CURLOPT_CUSTOMREQUEST=&gt;&quot;DELETE&quot;\r\n   \t\t\t\t ));\r\n   \t $resp = curl_exec($curl);\r\n   \t curl_close($curl);\r\n   \t var_dump($resp);\r\n?&gt;\r\n<\/pre><\/p>\n<p class=\"NormalTextDroid\">Here is the output:<\/p>\n<pre><span style=\"color: #999999;\">string(341) \"HTTP\/1.1 204 No Content Cache-Control: no-cache, no-store, max-age=0, must-revalidate \r\nPragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT Date: Thu, 25 May 2017 07:50:21 GMT ETag: \"m2yskBQFythfE4irbTIeOgYYfBU\/7MMpT8ZDo9n_QH3wl-DdyiOMn04\" \r\nVary: Origin Vary: X-Origin Server: GSE Alt-Svc: quic=\":443\"; \r\nma=2592000; v=\"37,36,35\" \"\r\n\r\n\r\n<\/span><\/pre>\n<p>Since this API calls does an HTTP DELETE command which is different from an HTTP POST, we specify\u00a0 CURLOPT_CUSTOMREQUEST as &#8220;DELETE&#8221;. We also set CURLOPT_HEADER to 1 as we need to check for the 204 response code, which signifies successful deletion.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is article 14 of the YouTube API With PHP series. The delete call deletes a specified Caption track. \u00a0The Request URL is \u00a0DELETE https:\/\/www.googleapis.com\/youtube\/v3\/captions\/ <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/07\/07\/14-youtube-data-api-captions-delete-function\/\" title=\"14 &#8211; YouTube Data API &#8211; Captions &#8211; delete function\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2727,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[318],"tags":[],"class_list":["post-2834","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-youtube-api-with-php"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=2834"}],"version-history":[{"count":1,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2834\/revisions"}],"predecessor-version":[{"id":2835,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2834\/revisions\/2835"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2727"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=2834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}