AppStoreはこちら → C#からApp Store Connect APIを叩いて売上レポートを取得する
悩んでググってこの記事に辿り着いた方向けの何の補足もない不親切な記事です。
公式のドキュメント
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Storage.V1;
const int year = 2022;
const int month = 12;
const string bucket = "~~~~~~~~~~~~";
const string tempFilePath = "temp.zip";
var credential = await GoogleCredential.GetApplicationDefaultAsync();
var client = await StorageClient.CreateAsync(credential);
var listObjects = client.ListObjects(bucket, "sales");
var o = listObjects.First(x => x.Name.Contains($"salesreport_{year:0000}{month:00}"));
await using var fileStream = File.Create(tempFilePath);
await client.DownloadObjectAsync(bucket, o.Name, fileStream);
落ちてくるのはcsvが1個入ってるだけのzipなので、適当にこんな感じで読めます。
private string async Task<byte[]> Decompress(string filePath)
{
using var zip = ZipFile.Open(filePath, ZipArchiveMode.Read);
var entry = zip.Entries.Single();
using var to = new MemoryStream();
await using var stream = entry.Open();
await stream.CopyToAsync(to);
return Encoding.UTF8.GetString(to.ToArray());
}