Last active
May 6, 2019 09:55
-
-
Save YuzuruSano/ed72a6418a0fd4a9d7957d4598e3593c to your computer and use it in GitHub Desktop.
Cloud Translate APIの利用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //キーの取得はこちらを参考に | |
| //https://alaki.co.jp/blog/?p=2636 | |
| require_once './vendor/autoload.php'; | |
| use Google\Cloud\Translate\TranslateClient; | |
| //「TranslateClient」クラスを呼び出し | |
| $translate = new TranslateClient([ | |
| 'projectId' => {プロジェクトID}, | |
| 'key' => {APIキー}, | |
| ]); | |
| // //翻訳開始 | |
| $result = $translate->translate('オッケーグーグル、明日の予定は?', [ | |
| 'target' => 'en',//翻訳したい言語を指定。今回は「日本語→英語」なので「en」 | |
| 'restOptions' => [//このオプション指定なしだと動かない | |
| 'headers' => [ | |
| 'referer' => {APIで許可したリファラに該当するもの} | |
| ] | |
| ] | |
| ]); | |
| echo '<pre>'; | |
| var_dump($result); | |
| echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment