{"id":3151,"date":"2022-02-23T10:03:56","date_gmt":"2022-02-23T01:03:56","guid":{"rendered":"https:\/\/blue-bear.jp\/kb\/?p=3151"},"modified":"2022-02-23T10:03:58","modified_gmt":"2022-02-23T01:03:58","slug":"yahoo%e3%82%ad%e3%83%bc%e3%83%95%e3%83%ac%e3%83%bc%e3%82%ba%e6%8a%bd%e5%87%baapiv2-%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0php","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/yahoo%e3%82%ad%e3%83%bc%e3%83%95%e3%83%ac%e3%83%bc%e3%82%ba%e6%8a%bd%e5%87%baapiv2-%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0php\/","title":{"rendered":"Yahoo!\u30ad\u30fc\u30d5\u30ec\u30fc\u30ba\u62bd\u51faAPI(v2) \u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0(PHP)"},"content":{"rendered":"\n<p>Yahoo!\u30ad\u30fc\u30d5\u30ec\u30fc\u30ba\u62bd\u51faAPI V1\u304c\u7d42\u4e86\u3057\u3066\u3057\u307e\u3044\u3001V2\u306b\u79fb\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8f09\u305b\u3066\u304a\u304f<\/p>\n\n\n\n<p>V1\u306fGET\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u9045\u308c\u305f\u304c\u3001V2\u306fJSON\u3092POST\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$sentence = \"\u8a55\u4fa1\u5bfe\u8c61\u306e\u6587\u7ae0\";\n\n$appid = '&lt;API\u30ad\u30fc\u3092\u5165\u529b>';\n\n$url = \"https:\/\/jlp.yahooapis.jp\/KeyphraseService\/V2\/extract\";\n\n$headers = &#91;\n    \"Content-Type: application\/json\",\n    \"User-Agent: Yahoo AppID: \".$appid,\n];\n\n$data = array(\n    \"id\" => \"1234-1\",\n    \"jsonrpc\" => \"2.0\",\n    \"method\" => \"jlp.keyphraseservice.extract\",\n    \"params\" => array(\n    \"q\" => $sentence\n    )\n);\n$data = json_encode($data);\n\n$curl = curl_init($url);\n$options = array(\n    \/\/ HEADER\n    CURLOPT_HTTPHEADER => $headers,\n    \/\/ Method\n    CURLOPT_POST => true, \/\/ POST\n    \/\/ body\n    CURLOPT_POSTFIELDS => $data,\n    \/\/ \u5909\u6570\u306b\u4fdd\u5b58\u3002\u3053\u308c\u304c\u306a\u3044\u3068\u5373\u6642\u51fa\u529b\n    CURLOPT_RETURNTRANSFER => true,\n    \/\/ header\u51fa\u529b\n    CURLOPT_HEADER => true, \n);\n\n\/\/set options\ncurl_setopt_array($curl, $options);\n\/\/\u53d6\u5f97\n$response = curl_exec($curl);\n\n\/\/\u30d8\u30c3\u30c0\u30fc\u53d6\u5f97\n$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); \n\/\/\u30d8\u30c3\u30c0\u30fc\u5207\u308a\u51fa\u3057\n$header = substr($response, 0, $header_size);\n\/\/BODY\u5207\u308a\u51fa\u3057\n$body = substr($response, $header_size);\n\/\/JSON\u306b\u5909\u63db\n$body = json_decode($body); \n\ncurl_close($curl);\n\n\/\/$body->result->phrases\u306b\u5404\u30d5\u30ec\u30fc\u30ba\u306e\u8981\u7d20\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\n\/\/$body->result->phrases->text\u304c\u30d5\u30ec\u30fc\u30ba\n$result_num = count($body->result->phrases);\n  \nif($result_num > 0){\n    for($i = 0; $i &lt; $result_num; $i++){\n      $result = $body->result->phrases&#91;$i];\n      $resultStr .= mb_convert_encoding(escapestring($result->text), 'utf-8', 'auto').\"\u3001\";\n    }\n}else{\n      $resultStr = \"\";\n}\n\n\/\/\u62bd\u51fa\u3055\u308c\u305f\u30d5\u30ec\u30fc\u30ba\u3092\u300c\u3001\u300d\u533a\u5207\u308a\u3067\u8868\u793a\necho $resultStr;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yahoo!\u30ad\u30fc\u30d5\u30ec\u30fc\u30ba\u62bd\u51faAPI V1<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[343,379,380],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3151"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=3151"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3151\/revisions"}],"predecessor-version":[{"id":3152,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3151\/revisions\/3152"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=3151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=3151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=3151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}