{"id":2888,"date":"2017-08-30T03:27:38","date_gmt":"2017-08-30T03:27:38","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2888"},"modified":"2017-08-30T03:27:38","modified_gmt":"2017-08-30T03:27:38","slug":"29-youtube-data-api-comments-setmoderationstatus-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/08\/30\/29-youtube-data-api-comments-setmoderationstatus-function\/","title":{"rendered":"29 &#8211; YouTube Data API &#8211; Comments &#8211; setModerationStatus 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 29 of the YouTube API With PHP series.<\/strong><\/p>\n<p>This function sets the moderation status of one or more comments. The API request must be authorized by the owner of the channel or video associated with the comments.<\/p>\n<p>The Request URL is<\/p>\n<p><span style=\"color: #808080;\">POST https:\/\/www.googleapis.com\/youtube\/v3\/comments\/setModerationStatus<\/span><\/p>\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 in certain cases. This is the user Access token.<\/li>\n<li><strong>id<\/strong> (string). Required. The id of the comment to be marked as spam.<\/li>\n<li><strong>moderationStatus<\/strong> (string) required. Identifies the new moderation status of the specified comments. Acceptable values are:\n<ul>\n<li>\u201cheldForReview\u201d \u2013 Marks a comment as awaiting review by a moderator.<\/li>\n<li>\u201cpublished\u201d \u2013 Clears a comment for public display.<\/li>\n<li>\u201crejected\u201d \u2013 Rejects a comment as being unfit for display. This action also effectively hides all replies to the rejected comment.<\/li>\n<\/ul>\n<\/li>\n<li><strong>banAuthor<\/strong> (boolean) Optional. This lets you indicate that you want to automatically reject any additional comments written by the comment&#8217;s author. Set the parameter value to true to ban the author. This parameter is only valid if the moderationStatus parameter is also set to \u201crejected\u201d.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Example Requests<\/strong><\/p>\n<p>Set moderation status for a comment<\/p>\n<p><span style=\"color: #808080;\">https:\/\/www.googleapis.com\/youtube\/v3\/comments\/setModerationStatus?key=xx&amp;access_token=&#8221; . $accessToken . &#8220;&amp;id=xx&amp;moderationStatus=rejected<\/span><\/p>\n<p>&nbsp;<\/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 set the moderation status of a comment.<br \/>\n<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 \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\/setModerationStatus?key=&quot; . $g_youtubeDataAPIKey .\r\n   \t\t\t  &quot;&amp;access_token=&quot; . $accessToken . &quot;&amp;id=&quot; . $commentId . &quot;&amp;moderationStatus=rejected&quot;;\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;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    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\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 07:20:50 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 29 of the YouTube API With PHP series. This function sets the moderation status of one or more comments. The API request <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/08\/30\/29-youtube-data-api-comments-setmoderationstatus-function\/\" title=\"29 &#8211; YouTube Data API &#8211; Comments &#8211; setModerationStatus 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-2888","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\/2888","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=2888"}],"version-history":[{"count":1,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2888\/revisions"}],"predecessor-version":[{"id":2890,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2888\/revisions\/2890"}],"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=2888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}