from Google import Create_Service import os API_NAME = 'photoslibrary' API_VERSION = 'v1' CLIENT_SECRET_FILE = 'clientGooglePhotos.json' SCOPES = [ 'https://www.googleapis.com/auth/photoslibrary', 'https://www.googleapis.com/auth/photoslibrary.sharing' ] service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) alb = service.albums() media = service.mediaItems()
API_VERSION = 'v1' SCOPES = ['https://www.googleapis.com/auth/photoslibrary'] service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) myAblums = service.albums().list().execute() myAblums_list = myAblums.get('albums') dfAlbums = pd.DataFrame(myAblums_list) travel_album_id = dfAlbums[dfAlbums['title'] == 'Travel']['id'].to_string( index=False).strip() def download_file(url: str, destination_folder: str, file_name: str): response = requests.get(url) if response.status_code == 200: print('Downloading file {0}'.format(file_name)) with open(os.path.join(destination_folder, file_name), 'wb') as f: f.write(response.content) f.close() media_files = service.mediaItems().search(body={ 'albumId': travel_album_id }).execute()['mediaItems'] destination_folder = r'.\Photos Backup' for media_file in media_files: file_name = media_file['filename'] download_url = media_file['baseUrl'] + '=d' download_file(download_url, destination_folder, file_name)
import os from Google import Create_Service API_NAME = 'photoslibrary' API_VERSION = 'v1' CLIENT_SECRET_FILE = 'credentials.json' SCOPES = [ 'https://www.googleapis.com/auth/photoslibrary', 'https://www.googleapis.com/auth/photoslibrary.sharing' ] service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES) listImage = [] response = service.mediaItems().list().execute() nextPageToken = response.get('nextPageToken') # while nextPageToken: # response = service.albums.list( # pageSize=50, # excludeNonAppCreatedData=False, # pageToken=nextPageToken # ) # listImage.append(response.get('ablums')) # nextPageToken = response.get('nextPageToken') randomItemId = response.get('mediaItems')[0].get('id') print(randomItemId) # create dummy album