我正在尝试通过Google Cloud Storage及其针对python googleapiclient
的客户端API库自动从Google Play下载收益报告。
我在Windows 10上使用python 3.6.5(Anaconda发行版):
client_email = '...@...iam.gserviceaccount.com'
json_file_path = 'C:\\Users\\...'
cloud_storage_bucket = 'pubsite_prod_rev_...'
report_to_download = 'sales/salesreport_201806.zip'
json_obj = json.loads(open(json_file).read())
_private_key = json_obj['private_key']
_private_key_id = json_obj['private_key_id']
_token_uri = json_obj['token_uri']
_client_id = json_obj['client_id']
credentials = ServiceAccountCredentials(
service_account_email = client_email,
private_key_id = _private_key_id,
token_uri = _token_uri,
client_id = _client_id,
scopes = 'https://www.googleapis.com/auth/devstorage.read_only',
signer = crypt.Signer.from_string(_private_key), )
storage = build('storage', 'v1', http=credentials.authorize(Http()))
request = storage.objects().get_media(bucket=cloud_storage_bucket,
object=report_to_download)
response = request.execute()
但是,我得到了一个协议缓冲文件,名为response
,它的开头是这样的:
b'PK\x03\x04\x14\x00\x08\x08\x08\x00\xdb\xa3\xe4L\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00PlayApps_201806.csv'
我无法确定应该使用哪种解码器来获得更好的格式response
(从Google Play手动下载时,报告是.csv
存档中的.zip
文件)。有什么建议吗?
答案 0 :(得分:0)
这不是protobuf。这是一个zip文件。线索