Google 照片 API mediaItems 只取前 25 项,我怎样才能取下一块?
Google Photo API mediaItems take only first 25 item, how can I take next chunk?
gphoto_service = googleapiclient.discovery.build(
'photoslibrary', 'v1', credentials=creds, static_discovery=False)
all_photos = gphoto_service.mediaItems().list().execute()
all_photos = all_photos['mediaItems']
len(all_photos)
输出:
25
按照上面的代码,我只能处理 Google 照片中所有照片的前 25 张。
事实上,有成千上万张照片。
我想一次需要 'chunk' 项才能节省内存。
但是我怎样才能得到 'next chunk' 张照片?
gphoto_service = googleapiclient.discovery.build(
'photoslibrary', 'v1', credentials=creds,
static_discovery=False)
# get first page (25 photos)
page_photos = gphoto_service.mediaItems().list().execute()
nextPageToken = page_photos['nextPageToken']
# get next page
page_photos = gphoto_service.mediaItems().list(
pageSize=25, pageToken=nextPageToken).execute()
nextPageToken = page_photos['nextPageToken']
gphoto_service = googleapiclient.discovery.build(
'photoslibrary', 'v1', credentials=creds, static_discovery=False)
all_photos = gphoto_service.mediaItems().list().execute()
all_photos = all_photos['mediaItems']
len(all_photos)
输出:
25
按照上面的代码,我只能处理 Google 照片中所有照片的前 25 张。 事实上,有成千上万张照片。 我想一次需要 'chunk' 项才能节省内存。
但是我怎样才能得到 'next chunk' 张照片?
gphoto_service = googleapiclient.discovery.build(
'photoslibrary', 'v1', credentials=creds,
static_discovery=False)
# get first page (25 photos)
page_photos = gphoto_service.mediaItems().list().execute()
nextPageToken = page_photos['nextPageToken']
# get next page
page_photos = gphoto_service.mediaItems().list(
pageSize=25, pageToken=nextPageToken).execute()
nextPageToken = page_photos['nextPageToken']