{"id":2859,"date":"2017-08-01T03:59:19","date_gmt":"2017-08-01T03:59:19","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2859"},"modified":"2017-08-01T03:59:19","modified_gmt":"2017-08-01T03:59:19","slug":"21-youtube-data-api-channel-sections-delete-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/08\/01\/21-youtube-data-api-channel-sections-delete-function\/","title":{"rendered":"21 &#8211; YouTube Data API &#8211; Channel Sections &#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 21 of the YouTube API With PHP series.<\/strong><\/p>\n<p>The delete function deletes an existing ChannelSection. This call requires user-authentication so only ChannelSections belonging to the current user can be deleted.<\/p>\n<p>The Request URL is<\/p>\n<pre><span style=\"color: #999999;\">DELETE https:\/\/www.googleapis.com\/youtube\/v3\/channelSections<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>key<\/strong> (string) required. Your API key<\/li>\n<li><strong>access_token<\/strong> (string) required. This is the user Access token.<\/li>\n<li><strong>id<\/strong> (string) required. A valid ChannelSection id<\/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>&nbsp;<\/p>\n<p><strong>Example Requests<\/strong><\/p>\n<p>Delete a ChannelSection<\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #999999;\">https:\/\/www.googleapis.com\/youtube\/v3\/channelSections?key=xx\u00a0\u00a0\u00a0\u00a0 &amp;access_token=xx &amp;id=xxxxx<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Response<\/strong><\/p>\n<p>On successful execution, a 204 http header will be received.<\/p>\n<p>Sample code to delete a ChannelSection<\/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    $g_youtubeDataAPIKey = &quot;**&quot;;\r\n    $channelId = &quot;UCo6DJdltbIub80bLiyJRv3w&quot;;\r\n    \r\n\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   \t \r\n   \t \r\n   \t $accessToken = $_SESSION[&quot;access_token&quot;];\r\n\r\n   \t \/\/ make api request\r\n   \t $url = &quot;https:\/\/www.googleapis.com\/youtube\/v3\/channelSections?key=&quot; . $g_youtubeDataAPIKey .\r\n   \t\t\t  &quot;&amp;access_token=&quot; . $accessToken . &quot;&amp;id=UCnXmfpAZ1rLsg0Goh0bBHUA.LeAltgu_pbM&quot;;\r\n\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\r\n   \t curl_close($curl);\r\n\r\n   \t var_dump($resp);\r\n   \t \r\n\r\n\r\n?&gt;\r\n<\/pre><\/p>\n<p>&nbsp;<\/p>\n<p>Here is the output:<\/p>\n<p><span style=\"color: #999999;\">string(344) &#8220;HTTP\/1.1 204 No Content Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT Date: Sat, 27 May 2017 07:03:19 GMT ETag: &#8220;m2yskBQFythfE4irbTIeOgYYfBU\/7MMpT8ZDo9n_QH3wl-DdyiOMn04&#8243; Vary: Origin Vary: X-Origin Server: GSE Alt-Svc: quic=&#8221;:443&#8243;; ma=2592000; v=&#8221;38,37,36,35&#8243; &#8220;<\/span><\/p>\n<p>The following things are required in the cURL Post:<\/p>\n<ul>\n<li>Put CURLOPT_HEADER as 1 since the response will return only headers<\/li>\n<li>Set CURLOPT_CUSTOMREQUEST to &#8220;DELETE&#8221; since this is not a POST<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is article 21 of the YouTube API With PHP series. The delete function deletes an existing ChannelSection. This call requires user-authentication so only ChannelSections <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/08\/01\/21-youtube-data-api-channel-sections-delete-function\/\" title=\"21 &#8211; YouTube Data API &#8211; Channel Sections &#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-2859","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\/2859","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=2859"}],"version-history":[{"count":2,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2859\/revisions"}],"predecessor-version":[{"id":2861,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2859\/revisions\/2861"}],"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=2859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}