Help us understand the problem. What is going on with this article?

GASで翻訳API作成してLaravelで叩くまで

はじめに

この記事では

GASで英語から日本語に翻訳するAPIを作成しLaravelで結果を取得までします

GASを作成

こちらの記事を参考に作成しました
3 分で作る無料の翻訳 API with Google Apps Script

controllerを作成

一部抜粋

TransController.php
    public function index() {

        $transApiUrl = '公開したAPIのURL';
        $transSource = 'en'; // 翻訳前の言語
        $transTarget = 'ja'; // 翻訳語の言語
        $transText = "Hello"; // 翻訳する文字

        $transApiUrl .= '?text=' . urlencode($transText);
        $transApiUrl .= '&source=' . $transSource;
        $transApiUrl .= '&target=' . $transTarget;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $transApiUrl);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $res = curl_exec($ch);
        curl_close($ch);



        return $res;
    }

GASの翻訳APIを叩く際に翻訳するテキスト量が多い際に
Moved Temporarily
The document has moved here.

と出ることがあります
これは

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
この記載を追加することで回避できます

叩いてみる

APIの配下にcontrollerを作成したので
ルーティングを以下に追記

api.php
Route::get('trans', 'Api\TransController@index')->name('trans');

http://127.0.0.1:8000/api/transにアクセス

結果

{"code":200,"text":"こんにちは"}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away