{"id":6536,"date":"2024-10-02T10:34:14","date_gmt":"2024-10-02T01:34:14","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6536"},"modified":"2024-10-03T16:57:39","modified_gmt":"2024-10-03T07:57:39","slug":"post-6536","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6536","title":{"rendered":"PHP\u306b\u3066\u300c\u307f\u3093\u306a\u306e\u81ea\u52d5\u7ffb\u8a33\u300d\u306eAPI\u3067\u6307\u5b9a\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u306e\u8a00\u8a9e\u5224\u5b9a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u8ff7\u60d1\u30e1\u30fc\u30eb\u5bfe\u7b56\u7b49\u3067\u30e1\u30fc\u30eb\u672c\u6587\u304c\u65e5\u672c\u8a9e\u306e\u3082\u306e\u306e\u307f\u53d7\u4fe1\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308b\u3002\u305f\u3060\u3001\u672c\u6587\u5185\u306bURL\u3084\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u5165\u308b\u3053\u3068\u3082\u3042\u308b\u3068\u601d\u308f\u308c\u308b\u306e\u3067\u6b63\u898f\u8868\u73fe\u3067\u3069\u3046\u3053\u3046\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u96e3\u3057\u305d\u3046\u3002\u305d\u3053\u3067\u300c\u307f\u3093\u306a\u306e\u81ea\u52d5\u7ffb\u8a33\u300d\u306e\u8a00\u8a9e\u5224\u5b9aAPI\u3092\u4f7f\u3048\u3070\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3063\u305f\u3002\u4ee5\u4e0b\u306b\u5229\u7528\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e8b\u524d\u6e96\u5099<\/h2>\n<p>\u300c\u307f\u3093\u306a\u306e\u81ea\u52d5\u7ffb\u8a33\u300d\u306b\u3064\u3044\u3066\u3068\u3001\u4e8b\u524d\u6e96\u5099\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/taitan916.info\/blog\/archives\/6532#i-3\" target=\"_blank\" rel=\"noopener\">\u904e\u53bb\u8a18\u4e8b<\/a>\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5229\u7528\u65b9\u6cd5<\/h2>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<p>\u5b9a\u6570\u90e8\u5206\u306f\u9069\u5b9c\u66f8\u304d\u63db\u3048\u308b\u3053\u3068\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\ndefine('API_KEY', 'xxxxxxxxxxxx');\r\ndefine('API_SECRET', 'xxxxxxxxxxxx');\r\ndefine('API_NAME', 'xxxxxxxxxxxx');\r\n\r\n\/\/\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u306e\u53d6\u5f97\r\n$token_url = 'https:\/\/mt-auto-minhon-mlt.ucri.jgn-x.jp\/oauth2\/token.php';\r\n$data = [\r\n    'grant_type' =&gt; 'client_credentials',\r\n    'client_id' =&gt; API_KEY,\r\n    'client_secret' =&gt; API_SECRET\r\n];\r\n$ch = curl_init();\r\ncurl_setopt($ch, CURLOPT_URL, $token_url);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\ncurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));\r\n\r\n$res = curl_exec($ch);\r\n$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n\r\nif( !curl_errno($ch) &amp;&amp; $http_code == '200' ){\r\n    $res = json_decode($res, true);\r\n    $access_token = $res['access_token'];\r\n}else{\r\n    echo 'ERROR: ' . curl_error($ch);\r\n    exit();\r\n}\r\ncurl_close($ch);\r\n\r\n\/\/\u7ffb\u8a33\r\n$translation_url = 'https:\/\/mt-auto-minhon-mlt.ucri.jgn-x.jp\/api\/langdetect\/';\r\n$text = \"Quickly translate text and document files, whether you're working as an individual or as a team.\u30c6\u30ad\u30b9\u30c8\u3084\u6587\u66f8\u30d5\u30a1\u30a4\u30eb\u3092\u77ac\u6642\u306b\u7ffb\u8a33\u3057\u307e\u3059\u3002\u500b\u4eba\u3067\u3082\u30c1\u30fc\u30e0\u3067\u3082\u3001\u9ad8\u7cbe\u5ea6\u306e\u7ffb\u8a33\u3092\u3054\u6d3b\u7528\u3044\u305f\u3060\u3051\u307e\u3059\u3002\";\r\n\r\n$data = [\r\n    'text' =&gt; $text,\r\n    'key' =&gt; API_KEY,\r\n    'access_token' =&gt; $access_token,\r\n    'name' =&gt; API_NAME,\r\n    'type' =&gt; 'json',\r\n];\r\n$ch = curl_init();\r\ncurl_setopt($ch, CURLOPT_URL, $translation_url);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\ncurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));\r\n\r\n$res = curl_exec($ch);\r\n$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\n\r\nif( !curl_errno($ch) &amp;&amp; $http_code == '200' ){\r\n    $res = json_decode($res, true);\r\n}else{\r\n    echo 'ERROR: ' . curl_error($ch);\r\n    exit();\r\n}\r\ncurl_close($ch);\r\n\r\nvar_dump($res['resultset']['result']);<\/pre>\n<h3>\u51fa\u529b\u7d50\u679c<\/h3>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300c\u8a00\u8a9e\u306f\u65e5\u672c\u8a9e\u3067\u985e\u4f3c\u5ea6\u304c91%\u300d\u3068\u3044\u3046\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u305f\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">array(1) {\r\n  [\"langdetect\"]=&gt;\r\n  array(1) {\r\n    [0]=&gt;\r\n    array(2) {\r\n      [\"lang\"]=&gt;\r\n      string(2) \"ja\"\r\n      [\"rate\"]=&gt;\r\n      float(0.91)\r\n    }\r\n  }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u8a00\u8a9e\u304c\u65e5\u672c\u8a9e\u4e14\u3064\u985e\u4f3c\u5ea6\u304c\u3007%\u4ee5\u4e0a\u306a\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u3001\u307f\u305f\u3044\u306a\u51e6\u7406\u3092\u5165\u308c\u308b\u3053\u3068\u3067\u8ff7\u60d1\u30e1\u30fc\u30eb\u5bfe\u7b56\u306b\u306a\u308a\u305d\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ff7\u60d1\u30e1\u30fc\u30eb\u5bfe\u7b56\u7b49\u3067\u30e1\u30fc\u30eb\u672c\u6587\u304c\u65e5\u672c\u8a9e\u306e\u3082\u306e\u306e\u307f\u53d7\u4fe1\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308b\u3002\u305f\u3060\u3001\u672c\u6587\u5185 ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6536"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6536\/revisions"}],"predecessor-version":[{"id":6538,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6536\/revisions\/6538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}