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()
import requests  # pip install requests

pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 150)
pd.set_option('display.max_colwidth', 150)
pd.set_option('display.width', 150)
pd.set_option('expand_frame_repr', True)

CLIENT_SECRET_FILE = 'client_secret_GoogleCloudDemo.json'
API_NAME = 'photoslibrary'
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()

Esempio n. 3
0
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
request_body = {'album': {'title': 'my dummy album'}}
response_album_family_photos = service.albums().create(
    body=request_body).execute()

# add some image to the dummy album
itemIs = [randomItemId]
request_body = {
    'mediaItemIds': [
        'APbOh8-u2CWkBL88OyEzWDZvR4GkBP3tEW-0cICtWB6q1kJ9ZSAW0clrEgY1V_kCXhET85XvGy0oH47q6IpJLoxwzKjKotXfgg'
    ]
}
reponse = service.albums().batchAddMediaItems(
    albumId=response_album_family_photos.get('id'),
    body=request_body).execute()

print(response)