使用Java App Engine从Google存储桶读取PlayStore csv审阅文件 [英] Reading PlayStore csv review files from Google storage bucket using Java App Engine

查看:154
本文介绍了使用Java App Engine从Google存储桶读取PlayStore csv审阅文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题困扰了我大部分时间.

This problem has stumped me for most part of my day.

背景

我正在尝试阅读 Play商店评论. 现在,我可以使用Google Cloud Storage客户端api(java)获取所有文件的列表. 我还可以读取该存储桶中每个csv文件的元数据并将其打印到日志中:

I am attempting to read the Play Store reviews for my Apps via my own Google App Engine Java project. Now I am able to get the list of all the files using Google Cloud Storage client api (java). I can also read the meta for each of the csv files in that bucket and print it to the logs:

问题

我根本无法找到一种方法来读取实际对象并获取csv数据. 我的Java代码段:

I simply can't find a way to read the actual object and get the csv data. My java code snippet:

BUCKET_NAME = "pubsite_prod_rev_*******";
objectFileName = "reviews/reviews_*****_***.csv"

Storage.Objects.Get obj = client.objects().get(BUCKET_NAME, objectFileName);
InputStream is = obj.executeMediaAsInputStream();

现在,当我打印此输入流时,它会告诉我其GZIPInputStream(java.util.zip.GZIPInputStream@f0be2c).将此输入流转换为byte []或String(所需)不起作用. 如果我尝试使用以下命令将其封装在GZIPInputStream对象中:

Now when I print this inputstream, it tells me its GZIPInputStream (java.util.zip.GZIPInputStream@f0be2c). Converting this inputstream to byte[] or String (desired) does not work. And if I try to envelope it inside GZIPInputStream object using:

zis = new GZIPInputStream(is);

它抛出 ZipException:不是GZIP格式.

文件的元数据:

"contentType": "text/csv; charset=utf-16le",
"contentEncoding": "gzip",

我在做什么错?

子问题:过去,我已经使用GcsService从Google云端存储中成功读取了文本数据,但似乎无法与具有Play商店审核csv文件的存储桶一起使用.有人知道我的Google App Engine项目(连接到相同的Google开发者帐户)是否可以读取这些存储桶?

Sub Question: In the past I have successfully read text data from Google Cloud Storage using GcsService, but it does not seem to work with the Buckets which have the Play Store review csv files. Does anybody know if my Google App Engine project (connected to same Google developer account) can read these Buckets?

推荐答案

使用executeMedia()和parseAsString解决了它

Solved it using executeMedia() and parseAsString

HttpResponse response = obj.executeMedia();
response.parseAsString(); //works!!

这篇关于使用Java App Engine从Google存储桶读取PlayStore csv审阅文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆