0
votes

I am trying to access the files in my one drive, here in python. So my code is as follow:

account = Account(credentials=credentials)

storage = account.storage()  # here we get the storage instance that handles all the storage options.

# list all the drives:
drives = storage.get_drives()

# get the default drive
my_drive = storage.get_default_drive()  # or get_drive('drive-id')
# get some folders:
root_folder = my_drive.get_root_folder()
attachments_folder = my_drive.get_special_folder('attachments')

# iterate over the first 25 items on the root folder
for item in root_folder.get_items(limit=25):
    if item.is_folder:
        print(list(item.get_items(2)))  # print the first to element on this folder.
    elif item.is_file:
        if item.is_photo:
            print(item.camera_model)  # print some metadata of this photo
        elif item.is_image:
            print(item.dimensions)  # print the image dimensions
        else:
            # regular file:
            print(item.mime_type)  # print the mime type

It throws this error: Client Error: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/me/drive/special/attachments | Error Message: Access denied

enter image description here enter image description here

I need help here, as you can see in the attached screenshot, I have defined the correct scopes as well. Have also checked similar articles but didn't find any luck.

Resource: https://pypi.org/project/O365/#onedrive

Thanks.

1
Check the access token by putting it in jwt.ms and see if the permissions are present or notShiva Keshav Varma
@ShivaKeshavVarma Yes you're right, I am applying all scopes : scopes=['basic', 'message_all', 'openid', 'email', 'profile', 'offline_access'] but the the token generated file it only shows { "token_type": "Bearer", "scope": [ "profile", "openid", "email", "graph.microsoft.com/Mail.ReadWrite", "graph.microsoft.com/Mail.Send", "graph.microsoft.com/User.Read" ] Could you please help me fix it? Thanksfreak7
@ShivaKeshavVarma Hey, this is solved. scopes that I didn't add "ReadWrite.All". Now it is working.freak7
Glad to here that :)-Shiva Keshav Varma

1 Answers

0
votes

Modify the scopes to : scopes=['basic', 'message_all', 'openid', 'email', 'profile', 'offline_access', 'onedrive', 'onedriveall']