You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to list all items (sharepoint documents) under a specific Site but I can't get more than 200 items (my site has 395 docs). The pagination doesn't seem to work.
Even adding top(1000) doesn't work.
How can I get a list of all objects (drive items) for my Site?
importioimportosfromtypingimportAnyfromoffice365.graph_clientimportGraphClient# type: ignorefromoffice365.onedrive.driveitems.driveItemimportDriveItem# type: ignorefromoffice365.onedrive.sites.siteimportSite# type: ignoreclassSharepointConnector():
def__init__(
self,
) ->None:
self.graph_client: GraphClient|None=Nonedefload_credentials(self, credentials: dict[str, Any]) ->dict[str, Any] |None:
aad_client_id=credentials["aad_client_id"]
aad_client_secret=credentials["aad_client_secret"]
aad_directory_id=credentials["aad_directory_id"]
def_acquire_token_func() ->dict[str, Any]:
""" Acquire token via MSAL """authority_url=f"https://login.microsoftonline.com/{aad_directory_id}"app=msal.ConfidentialClientApplication(
authority=authority_url,
client_id=aad_client_id,
client_credential=aad_client_secret,
)
token=app.acquire_token_for_client(
scopes=["https://graph.microsoft.com/.default"]
)
returntokenself.graph_client=GraphClient(_acquire_token_func)
defget_all_driveitem_objects(
self,
) ->list[DriveItem]:
site_object=self.graph_client.sites.get_by_url("https://XXXX.sharepoint.com/sites/library")
driveitem_list= []
site_list_objects=site_object.lists.get().execute_query()
forsite_list_objectinsite_list_objects:
try:
query=site_list_object.drive.root.get_files(True)
driveitems=query.execute_query()
driveitem_list.extend(driveitems)
exceptExceptionase:
# Sites include things that do not contain .drive.root so this fails# but this is fine, as there are no actually documents in thosepassreturndriveitem_listif__name__=='__main__':
sc=SharepointConnector()
sc.load_credentials(
{
"aad_client_id": os.environ["AAD_CLIENT_ID"],
"aad_client_secret": os.environ["AAD_CLIENT_SECRET"],
"aad_directory_id": os.environ["AAD_CLIENT_DIRECTORY_ID"],
}
)
sc.get_all_driveitem_objects()
The text was updated successfully, but these errors were encountered:
Greetings,
thank you for catching this issue and providing the detailed info!
Even adding top(1000) doesn't work.
indeed, it was not honored in DriveItem.get_filles(recursive, page_size) method. In a new version (2.5.9) the the method is expected to return all the items, no matter whether collection exceeds the default page size or not.
Hi,
I'm trying to list all items (sharepoint documents) under a specific Site but I can't get more than 200 items (my site has 395 docs). The pagination doesn't seem to work.
Even adding
top(1000)
doesn't work.How can I get a list of all objects (drive items) for my Site?
The text was updated successfully, but these errors were encountered: