{"id":2884,"date":"2017-08-27T04:54:34","date_gmt":"2017-08-27T04:54:34","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2884"},"modified":"2017-08-30T03:24:06","modified_gmt":"2017-08-30T03:24:06","slug":"28-youtube-data-api-comments-markasspam-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/08\/27\/28-youtube-data-api-comments-markasspam-function\/","title":{"rendered":"28 &#8211; YouTube Data API &#8211; Comments &#8211; markAsSpam 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 28 of the YouTube API With PHP series.<\/strong><\/p>\n<p>markAsSpam function expresses the current user\u2019s opinion that one or more comments should be flagged as spam. This is the API equivalent of marking a comment or a reply as Spam in YouTube. You can use this for any public comment or reply in any publicly visible Channel or Video. This call requires user-authentication as anonymous users are not allowed to mark comments as spam.<\/p>\n<p>Note that this wont automatically mark the comment as spam. It will just send notification for that.<\/p>\n<p>The Request URL is<\/p>\n<pre><span style=\"color: #808080;\">POST https:\/\/www.googleapis.com\/youtube\/v3\/comments\/markAsSpam<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Parameters<br \/>\n<\/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. The id of the comment to update.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Example Requests<\/strong><\/p>\n<p>Mark a comment as spam.<\/p>\n<p><span style=\"color: #808080;\">https:\/\/www.googleapis.com\/youtube\/v3\/comments\/markAsSpam?key=xx&amp;access_token=xx&amp;id=xx<\/span><\/p>\n<p><strong>Response<\/strong><\/p>\n<p>On successful execution his 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 mark a comment as spam:<\/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.1496034554121428&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 $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\/markAsSpam?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 $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;POST&quot;,\r\n   \t\t\t\t CURLOPT_POSTFIELDS=&gt;&quot;&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    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>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 06:48:39 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 cURL request should have the following things:<\/p>\n<ul>\n<li>Set CURLOPT_HEADER to 1 as the response will contain a header<\/li>\n<li>Set CURLOPT_CUSTOMREQUEST to &#8220;POST&#8221; even though there is no data being sent.<\/li>\n<li>Set CURLOPT_POSTFIELDS to an empty string.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is article 28 of the YouTube API With PHP series. markAsSpam function expresses the current user\u2019s opinion that one or more comments should be <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/08\/27\/28-youtube-data-api-comments-markasspam-function\/\" title=\"28 &#8211; YouTube Data API &#8211; Comments &#8211; markAsSpam 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-2884","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\/2884","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=2884"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2884\/revisions"}],"predecessor-version":[{"id":2889,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2884\/revisions\/2889"}],"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=2884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}