diff --git a/guides/ja-JP/use-case-guides/reports-api-use-case-guide/reports-api-v2021-06-30-retrieve-a-report-html-en_us-ja_jp.html b/guides/ja-JP/use-case-guides/reports-api-use-case-guide/reports-api-v2021-06-30-retrieve-a-report-html-en_us-ja_jp.html new file mode 100644 index 0000000..4a4fe26 --- /dev/null +++ b/guides/ja-JP/use-case-guides/reports-api-use-case-guide/reports-api-v2021-06-30-retrieve-a-report-html-en_us-ja_jp.html @@ -0,0 +1,739 @@ + + +
+ + +このガイドの最新版は、https://developer-docs.amazon.com/sp-api/docs/reports-api-v2021-06-30-retrieve-a-reportをご覧ください。
APIバージョン: 2021-06-30
レポートドキュメントを取得するために必要な情報を得て、レポートをダウンロードします。
getReportDocumen
オペレーションを呼び出して、レポートドキュメントの内容を取得するために必要な情報を得ます。これには、レポートドキュメントの署名付きURLが含まれており、オプションで、レポートドキュメントの内容が圧縮されている場合は、圧縮アルゴリズムが使用されています。
getReportDocument
オペレーションを呼び出して、以下のパラメーターを渡します。パスのパラメーター:
+ 名前 + | ++ 説明 + | ++ 必須 + | +
---|---|---|
reportDocumentId |
+ レポートドキュメントのID。 タイプ:string + |
+ はい | +
xxxxxxxxxx
GET https://sellingpartnerapi-na.amazon.com/reports/2021-06-30/documents/DOC-b8b0-4226-b4b9-0ee058ea5760
レスポンス
成功レスポンスには、以下が含まれます。
+ 名前 + | ++ 説明 + | +
---|---|
reportDocumentId |
+ レポートドキュメントのID。このIDは、出品者IDと組み合わせた場合のみ一意です。 | +
url |
+
+ レポートドキュメントの署名付きURL。このURLは5分後に失効します。
+ タイプ:string + |
+
compressionAlgorithm |
+ これがある場合、レポートドキュメントの内容は、指定されたアルゴリズムで圧縮されています。 タイプ:列挙( |
+
xxxxxxxxxx
{
"reportDocumentId": "DOC-b8b0-4226-b4b9-0ee058ea5760",
"url": "https://d34o8swod1owfl.cloudfront.net/SampleResult%2BKey%3DSample%2BINITVEC%3D58+fa+bf+a7+08+11+95+0f+c1+a8+c6+e0+d5+6f+ae+c8"
}
url
を保存して、ステップ2のcompressionAlgorithm
(オプションのプロパティ)で使用します。ステップ1で返された情報を使用して、レポートをダウンロードする必要があります。以下のサンプルコードは、プレーンテキストのレポートドキュメントをダウンロードする方法を示しています。このサンプルコードに示されている原則は、他のプログラミング言語や、他のドキュメントタイプ(XML、CSV、TSVなど)のアプリケーション構築のガイダンスとして使用することもできます。
サンプルコードの入力に以下を使用します。
url
値とオプションのcompressionAlgorithm
値は、DownloadExample
クラスのdownload
メソッドのurl
とcompressionAlgorithm
パラメーターの引数です。注: 保管中は常に暗号化を維持する必要があります。暗号化されていないレポートコンテンツは、一時的であってもディスクに保存しないでください。レポートに機密情報が含まれている可能性があります。提供するサンプルコードは、この原則を示しています。
// DownloadExample.java
// これは、以下での使用例です。Selling Partner API for Reportsのバージョン: 2021-06-30
// およびSelling Partner API for Feedsのバージョン: 2021-06-30
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;
+
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
+
/**
* ドキュメントをダウンロードする例。
*/
public class DownloadExample {
+
public static void main(String args[]) {
String url = "<getFeedDocument/getReportDocumentレスポンスのURL>";
String compressionAlgorithm = "<getFeedDocument/getReportDocumentレスポンスのcompressionAlgorithm>";
+
DownloadExample obj = new DownloadExample();
try {
obj.download(url, compressionAlgorithm);
} catch (IOException e) {
//ここで例外を処理します。
} catch (IllegalArgumentException e) {
//ここで例外を処理します。
}
}
+
/**
* 指定されたURLから取得したドキュメントをダウンロードし、必要に応じて解凍します。
*
* @param url ドキュメントを指すURL
* @param compressionAlgorithm ドキュメントに使用されたcompressionAlgorithm
* @throws IOException レスポンスの読み取り中にエラーが発生した場合
* @throws IllegalArgumentException その文字セットがない場合
*/
public void download(String url, String compressionAlgorithm) throws IOException, IllegalArgumentException {
OkHttpClient httpclient = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.get()
.build();
+
Response response = httpclient.newCall(request).execute();
if (!response.isSuccessful()) {
System.out.println(
String.format("コンテンツをダウンロードする呼び出しは失敗しました。レスポンスコード:%d、メッセージ:%s",
response.code(), response.message()));
return;
}
+
try (ResponseBody responseBody = response.body()) {
MediaType mediaType = MediaType.parse(response.header("Content-Type"));
Charset charset = mediaType.charset();
if (charset == null) {
throw new IllegalArgumentException(String.format(
"'%s'の文字セットを解析できませんでした", mediaType.toString()));
}
+
Closeable closeThis = null;
try {
InputStream inputStream = responseBody.byteStream();
closeThis = inputStream;
+
if ("GZIP".equals(compressionAlgorithm)) {
inputStream = new GZIPInputStream(inputStream);
closeThis = inputStream;
}
+
// この例では、ダウンロードコンテンツのContent-Typeヘッダーなどに文字セットがあることを前提としています。
// text/plain; charset=UTF-8
if ("text".equals(mediaType.type()) && "plain".equals(mediaType.subtype())) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, charset);
closeThis = inputStreamReader;
+
BufferedReader reader = new BufferedReader(inputStreamReader);
closeThis = reader;
+
String line;
do {
line = reader.readLine();
// 1行ずつ処理します。
} while (line != null);
} else {
//ここでバイナリデータ/その他のメディアタイプのコンテンツを処理します。
}
} finally {
if (closeThis != null) {
closeThis.close();
}
}
}
}
}