Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
313 stars 44 forks source link

Accessing Shared OneDrive files #45

Closed domsle closed 3 years ago

domsle commented 3 years ago

Is it possible to access files that have been shared with me? When I am listing files with odb$list_items(), I only see files in my own OneDrive directory. Is there any way to access other peoples' shared files?

hongooi73 commented 3 years ago

There's no built-in method for this right now, but you can get the list by calling the REST API directly:

sh <- odb$do_operation("sharedWithMe", options=list(allowexternal="true"))
objs <- lapply(sh$value, function(obj) ms_drive_item$new(odb$token, odb$tenant, obj$remoteItem))

This will work for the first 200 shared items. I'll look into getting a proper implementation into the next version.

domsle commented 3 years ago

Thank you for the reply. It works perfectly.

In this case, I am waiting for the feature to be added in next version :)

SchmidtPaul commented 1 year ago

Hi, @hongooi73 I am also interested in this. I am looking for the content of a specific folder that was shared with me. I think I found the folder via your suggestion because this

sh <- odb$do_operation("sharedWithMe", options=list(allowexternal="true"))
sh$value[[1]]$remoteItem$webUrl

does lead to the correct URL.

However, I am now interested in subfolders of it. More specifically, my ultimate goal is to get the names of all folders within Folder/Subfolder/, where Folder is the one I found above and thus I need all folders:

Edit: Solved it

I figured it out:

odb <- get_business_onedrive()
sh <- odb$do_operation("sharedWithMe", options=list(allowexternal="true"))
sh_i <- sh$value[[1]]$remoteItem
folder <- ms_drive_item$new(odb$token, odb$tenant, sh_i)
subfolder <- folder$get_item("SubFolder")
subsubfolders <- subfolder$list_files()
subset(subsubfolders, isdir)$name