예제 #1
0
def upload(item_path, upload_type, file_path):
    # Initialize the Graph Client.
    graph_client = MicrosoftGraphClient(
        client_id=client_id,
        client_secret=client_secret,
        redirect_uri=redirect_uri,
        scope=scopes,
        credentials='config/ms_graph_state.jsonc')

    # Login
    graph_client.login()

    # Grab the Drive Item services
    drive_item_services = graph_client.drive_item()

    # Create an upload session
    upload_session = drive_item_services.create_upload_session(
        item_path=item_path, item=upload_type)

    drive_item_services.upload_large_file(upload_session['uploadUrl'],
                                          file_path)
config.read('config/config.ini')

# Get the specified credentials.
client_id = config.get('graph_api', 'client_id')
client_secret = config.get('graph_api', 'client_secret')
redirect_uri = config.get('graph_api', 'redirect_uri')

# Initialize the Client.
graph_client = MicrosoftGraphClient(client_id=client_id,
                                    client_secret=client_secret,
                                    redirect_uri=redirect_uri,
                                    scope=scopes,
                                    credentials='config/ms_graph_state.jsonc')

# Login to the Client.
graph_client.login()

# Define a valid User ID.
user_id = '8bc640c57cda25b6'

# Define a mail Item ID.
mail_id = 'AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb_dak68rN7703u' + \
          'ffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEhAAAAFNKsLOjbGUuHHmYnyKdJiAAFBMTneQAAAA=='

# Define a mail item ID with Attachments.
mail_id_with_attachments = 'AQMkADAwATZiZmYAZC1hMDI2LTE3NTgtMDACLTAwCgBGAAADpjqwNb+' + \
                           'dak68rN7703uffQcAFNKsLOjbGUuHHmYnyKdJiAAAAgEMAAAAFNKsLOjbGUuHHmYnyKdJiAAE9ucV+AAAAA=='

# Grab the Notes Services.
mail_services = graph_client.mail()