LoginSignup
0
0

[Google Cloud Text-to-Speech API(V1)] Javaで長時間実行オペレーションをキャンセル・削除する

Posted at

Cloud Text-to-Speech API V1(Java)を使用して、
長時間実行オペレーションをキャンセル・削除する方法についてご紹介します。

APIを利用する環境の準備から始める場合や、コードを実行する際は、
⧉[Google Cloud Text-to-Speech API(V1)] JavaでText-to-Speech APIを使ってみる
を参照ください。

No 目次
1 オペレーションをキャンセル
1 スコープ
2 実行
3 レスポンスの内容
2 オペレーションを削除
1 スコープ
2 実行
3 レスポンスの内容

1. オペレーションをキャンセル

指定した長時間実行オペレーションをキャンセルします。

1.1. スコープ

OAuth2.0でこのAPIを実行するには、以下のスコープを指定してください。
サービスアカウントで実行する場合はスコープの指定は不要です。

https://www.googleapis.com/auth/cloud-platform

1.2. 実行

public static void main(String[] args) throws Exception{
    try(TextToSpeechLongAudioSynthesizeClient client = getTextToSpeechLongAudioSynthesizeClient();
        OperationsClient op = client.getOperationsClient()){
    
        String opName = String.format(
                        "projects/%s/locations/%s/operations/%s", 
                        "プロジェクトID","ロケーションID","オペレーションID");
        op.cancelOperation(opName);
    }
}

1.2.1. HTTPリクエスト

POST: https://texttospeech.googleapis.com/v1/operations/projects/{プロジェクトID}/locations/{ロケーションID}/operations/{オペレーションID}:cancel
が実行されます。

1.2.2. クエリパラメータ

クエリパラメータはありません。

1.2.3. リクエストボディ

リクエストボディはありません。

1.3. レスポンスの内容

レスポンスはありません。

2. オペレーションを削除

指定した長時間実行オペレーションを削除します。

2.1. スコープ

OAuth2.0でこのAPIを実行するには、以下のスコープを指定してください。
サービスアカウントで実行する場合はスコープの指定は不要です。

https://www.googleapis.com/auth/cloud-platform

2.2. 実行

public static void main(String[] args) throws Exception{
    try(TextToSpeechLongAudioSynthesizeClient client = getTextToSpeechLongAudioSynthesizeClient();
        OperationsClient op = client.getOperationsClient()){
    
        String opName = String.format(
                        "projects/%s/locations/%s/operations/%s", 
                        "プロジェクトID","ロケーションID","オペレーションID");
        op.deleteOperation(opName);
    }
}

2.2.1. HTTPリクエスト

DELETE: https://texttospeech.googleapis.com/v1/projects/{プロジェクトID}/locations/{ロケーションID}/operations/{オペレーションID}
が実行されます。

2.2.2. クエリパラメータ

クエリパラメータはありません。

2.2.3. リクエストボディ

リクエストボディはありません。

2.3. レスポンスの内容

レスポンスはありません。



おしまい。。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0