更新 :以下内容适用于Python的旧版“ Google API客户端库”,但如果您不使用该客户端,则更喜欢适用于Python的较新的“
Google Cloud Client Library”(https://googleapis.dev/python/ storage / latest
/
index.html)。对于较新的库,与以下代码等效:
from google.cloud import storageclient = storage.Client()for blob in client.list_blobs('bucketname', prefix='abc/myfolder'): print(str(blob))老年客户的答案如下。
您可能会发现,使用具有完整功能的Python客户端的JSON
API更容易。它具有一个列出带有前缀参数的对象的功能,您可以通过这种方式检查某个目录及其子目录:
from apiclient import discovery# Auth goes here if necessary. Create authorized http object...client = discovery.build('storage', 'v1') # add http=whatever param if authrequest = client.objects().list( bucket="mybucket", prefix="abc/myfolder")while request is not None: response = request.execute() print json.dumps(response, indent=2) request = request.list_next(request, response)列表调用的完整文档在这里:https://developers.google.com/storage/docs/json_api/v1/objects/list
此处记录了Google Python API客户端:https : //pre.google.com/p/google-api-python-
client/



