{"id":2894,"date":"2017-09-11T03:32:46","date_gmt":"2017-09-11T03:32:46","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2894"},"modified":"2017-09-11T03:32:46","modified_gmt":"2017-09-11T03:32:46","slug":"31-youtube-data-api-guide-categories-list-function","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2017\/09\/11\/31-youtube-data-api-guide-categories-list-function\/","title":{"rendered":"31 &#8211; YouTube Data API &#8211; Guide Categories &#8211; list 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 31 of the YouTube API With PHP series.<\/strong><\/p>\n<p>A GuideCategory resource identifies a category that YouTube algorithmically assigns based on a channel&#8217;s content or other indicators, such as the channel&#8217;s popularity. The list is similar to video categories, with the difference being that a video&#8217;s uploader can assign a video category but only YouTube can assign a channel category.<\/p>\n<p>This is not to be confused with the Video categories list. If you want a list of available Video Categories, then you should check the Video Categories resource. The Guide Category will only return recommended categories. In some cases, there may not be any Guide Categories.<\/p>\n<p>Every guide category has a Channel associated with it. These Channels are created by Youtube and are not user-created.<\/p>\n<p>The following function is available.<\/p>\n<p><strong>1.list<\/strong><\/p>\n<p>Returns a list of categories that can be associated with YouTube channels.<\/p>\n<p>The Request URL is<\/p>\n<pre><span style=\"color: #999999;\">GET https:\/\/www.googleapis.com\/youtube\/v3\/guideCategories<\/span><\/pre>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li><strong>key<\/strong> (string) required. Your API key<\/li>\n<li><strong>part<\/strong> (string). Required. Only this value is valid:\n<ul>\n<li>\u201csnippet\u201d<\/li>\n<\/ul>\n<\/li>\n<li>Filters (string) required. One of the following:\n<ul>\n<li><strong>id<\/strong> (string) This specifies a comma-separated list of video category IDs for the resources that you are retrieving.<\/li>\n<li><strong>regionCode<\/strong> (string) This instructs the API to return the list of guide categories available in the specified country. The parameter value is a two letter country code.<\/li>\n<\/ul>\n<\/li>\n<li><strong>hl<\/strong> (string) optional. The hl parameter specifies the language that will be used for text values in the API response. The default value is en-US.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Example Requests<\/strong><\/p>\n<p>Get guide categories for a particular country<\/p>\n<p><span style=\"color: #999999;\">https:\/\/www.googleapis.com\/youtube\/v3\/guideCategories?key=xx&amp;part=snippet&amp;regionCode=xx<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Get guide categories for a Channel category<\/p>\n<p><span style=\"color: #999999;\">https:\/\/www.googleapis.com\/youtube\/v3\/guideCategories?key=xx&amp;part=snippet&amp;id=xx<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Response<\/strong><\/p>\n<p>A successful API call will return an array of GuideCategory resources encoded in json:<\/p>\n<pre><span style=\"color: #999999;\">{<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"kind\": \"youtube#guideCategoryListResponse\",<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"etag\": etag,<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"nextPageToken\": string,<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"prevPageToken\": string,<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"pageInfo\": {<\/span>\r\n<span style=\"color: #999999;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"totalResults\": integer,<\/span>\r\n<span style=\"color: #999999;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"resultsPerPage\": integer<\/span>\r\n<span style=\"color: #999999;\">\u00a0 },<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"items\": [<\/span>\r\n<span style=\"color: #999999;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (guideCategory resource)<\/span>\r\n<span style=\"color: #999999;\">\u00a0 ]<\/span>\r\n<span style=\"color: #999999;\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>The Response components are explained below:<\/p>\n<ul>\n<li><strong>kind<\/strong> (string) \u201cyoutube#guideCategoryListResponse\u201d<\/li>\n<li><strong>etag<\/strong> (string) See ETags Explained section<\/li>\n<li><strong>nextPageToken<\/strong> (string) token for the next page<\/li>\n<li><strong>prevPageToken<\/strong> (string) token for the previous page<\/li>\n<li><strong>totalResults<\/strong> (int) total count of results obtained<\/li>\n<li><strong>resultsPerPage<\/strong> (int) results per page requested<\/li>\n<li><strong>items<\/strong> (array) array of GuideCategory Resource items returned<\/li>\n<\/ul>\n<p>The JSON structure of a GuideCategory Resource is shown below:<\/p>\n<pre><span style=\"color: #999999;\">{<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"kind\": \"youtube#guideCategory\",<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"etag\": etag,<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"id\": string,<\/span>\r\n<span style=\"color: #999999;\">\u00a0 \"snippet\": {<\/span>\r\n<span style=\"color: #999999;\">\u00a0\u00a0\u00a0\u00a0 \"channelId\": \"UCBR8-60-B28hp2BmDPdntcQ\",<\/span>\r\n<span style=\"color: #999999;\">\u00a0\u00a0\u00a0\u00a0 \"title\": string<\/span>\r\n<span style=\"color: #999999;\">\u00a0 }<\/span>\r\n<span style=\"color: #999999;\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>An explanation of the various fields are given below:<\/p>\n<ul>\n<li><strong>kind<\/strong> (string) This value is always \u201cyoutube#guideCategory\u201d<\/li>\n<li>etag (string) See ETags Explained section<\/li>\n<li><strong>id<\/strong> (string) The ID that YouTube uses to uniquely identify the guide category.<\/li>\n<li><strong>channelId<\/strong> (string) The ID that YouTube uses to uniquely identify the channel publishing the guide category.<\/li>\n<li><strong>title<\/strong> (string) The category&#8217;s title.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Sample code to get all the guideCategories for a country:<\/p>\n<p><pre class=\"brush: php\">&lt;?php\r\n    error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);\r\n    session_start();\r\n    set_time_limit(60 * 3);\r\n    \r\n    $g_youtubeDataAPIKey = &quot;**&quot;;\r\n    $channelId = &quot;UCIJ0lLcABPdYGp7pRMGccAQ&quot;;\r\n    \r\n\r\n    $_SESSION[&quot;code_id&quot;] = $_SERVER[&quot;PHP_SELF&quot;];\r\n\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\r\n   \t \/\/ make api request\r\n   \t $url = &quot;https:\/\/www.googleapis.com\/youtube\/v3\/guideCategories?key=&quot; . $g_youtubeDataAPIKey .\r\n   \t\t\t   &quot;&amp;part=snippet&reg;ionCode=au&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_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 ));\r\n   \t $resp = curl_exec($curl);\r\n\r\n   \t curl_close($curl);\r\n    \r\n   \t \r\n   \t if ($resp) {\r\n   \t\t $json = json_decode($resp);\r\n   \t\t if ($json) {\r\n   \t\t\t echo(&quot;JSON decoded&lt;br&gt;&quot;);\r\n   \t\t\t $total = $json-&gt;pageInfo-&gt;totalResults;\r\n   \t\t\t echo($total . &quot; categories found.&lt;br&gt;&lt;br&gt;&quot;);\r\n   \t\t\t $items = $json-&gt;items;\r\n\r\n   \t\t\t foreach($items as $item) {\r\n   \t\t\t\t $id = $item-&gt;id;\r\n   \t\t\t\t $channelId = $item-&gt;snippet-&gt;channelId;\r\n   \t\t\t\t $title = $item-&gt;snippet-&gt;title;\r\n\r\n   \t\t\t\t echo(&quot;id :&quot; . $id . &quot; Channel id: &quot; . $channelId . &quot;&lt;br&gt;&quot;);\r\n   \t\t\t\t echo($title . &quot;&lt;hr&gt;&quot;);\r\n   \t\t\t }\r\n   \t\t }\r\n   \t\t else\r\n   \t\t\t exit(&quot;Error. could not parse JSON.&quot; . json_last_error_msg());\r\n\r\n   \t \r\n   \t } \/\/ if resp\r\n   \t \r\n    \r\n?&gt;\r\n<\/pre><\/p>\n<p>Here is the Output:<\/p>\n<pre>\r\n<span style=\"color: #999999;\">JSON decoded<\/span>\r\n<span style=\"color: #999999;\">id :GCQmVzdCvZiBZb3VUdWJl Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Best of YouTube<\/span>\r\n<span style=\"color: #999999;\">id :GCQ3JlYXRvciBvbiB0aGUgUmlzZQ Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Creator on the Rise<\/span>\r\n<span style=\"color: #999999;\">id :GCTXVzaWM Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Music<\/span>\r\n<span style=\"color: #999999;\">id :GCQ29tZWR5 Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Comedy<\/span>\r\n<span style=\"color: #999999;\">id :GCRmlsbSAmIEVudGVydGFpbm1lbnQ Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Film &amp; Entertainment<\/span>\r\n<span style=\"color: #999999;\">id :GCR2FtaW5n Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Gaming<\/span>\r\n<span style=\"color: #999999;\">id :GCQmVhdXR5ICYgRmFzaGlvbg Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Beauty &amp; Fashion<\/span>\r\n<span style=\"color: #999999;\">id :GCU3BvcnRz Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Sports<\/span>\r\n<span style=\"color: #999999;\">id :GCVGVjaA Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Tech<\/span>\r\n<span style=\"color: #999999;\">id :GCQ29va2luZyAmIEhlYWx0aA Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">Cooking &amp; Health<\/span>\r\n<span style=\"color: #999999;\">id :GCTmV3cyAmIFBvbGl0aWNz Channel id: UCBR8-60-B28hp2BmDPdntcQ<\/span>\r\n<span style=\"color: #999999;\">News &amp; Politics\r\n\r\n\r\n<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>This is article 31 of the YouTube API With PHP series. A GuideCategory resource identifies a category that YouTube algorithmically assigns based on a channel&#8217;s <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2017\/09\/11\/31-youtube-data-api-guide-categories-list-function\/\" title=\"31 &#8211; YouTube Data API &#8211; Guide Categories &#8211; list 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-2894","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\/2894","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=2894"}],"version-history":[{"count":2,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2894\/revisions"}],"predecessor-version":[{"id":2896,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2894\/revisions\/2896"}],"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=2894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}