{"id":2891,"date":"2017-09-02T04:11:53","date_gmt":"2017-09-02T04:11:53","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2891"},"modified":"2017-09-02T04:11:53","modified_gmt":"2017-09-02T04:11:53","slug":"30-youtube-data-api-comments-delete-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/09\/02\/30-youtube-data-api-comments-delete-function\/","title":{"rendered":"30 &#8211; YouTube Data API &#8211; Comments &#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 30 of the YouTube API With PHP series.<\/strong><\/p>\n<p>The delete function deletes a comment either posted by the current user, or posted to a Video or Channel owned by the current user. This call requires user-authentication.<\/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 in certain cases. This is the user Access token.<\/li>\n<li><strong>id<\/strong> (string). Required. Id of the comment.<\/li>\n<\/ul>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Example Requests<\/strong><\/p>\n<p>Delete a comment.<\/p>\n<pre><span style=\"color: #808080;\">https:\/\/www.googleapis.com\/youtube\/v3\/comments?key=xx&amp;access_token=xx&amp;id=xx<\/span><\/pre>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>Response<\/strong><\/p>\n<p>On successful execution this method returns an HTTP 204 response code (No Content). If you specify a non-existent comment id then the call will fail.<\/p>\n<p>Sample code to delete a comment:<\/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\r\n    $commentId = &quot;z12jy3qp3q21e3se322ttjmaqlimxxohg04.1496042388885297&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   \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\/comments?key=&quot; . $g_youtubeDataAPIKey .\r\n   \t\t\t  &quot;&amp;access_token=&quot; . $accessToken . &quot;&amp;id=&quot; . $commentId;\r\n\r\n   \t \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\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    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\r\n    class Comment {\r\n   \t public $snippet;\r\n   \t public $id;\r\n    }\r\n\r\n    class Snippet {\r\n   \t public $textOriginal;\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: #808080;\">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: Mon, 29 May 2017 05:22:36 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","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is article 30 of the YouTube API With PHP series. The delete function deletes a comment either posted by the current user, or posted <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/09\/02\/30-youtube-data-api-comments-delete-function\/\" title=\"30 &#8211; YouTube Data API &#8211; Comments &#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-2891","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\/2891","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=2891"}],"version-history":[{"count":1,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2891\/revisions"}],"predecessor-version":[{"id":2892,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2891\/revisions\/2892"}],"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=2891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}