Manage users in SharePoint: who has access to a site, current user info,
tenant-wide search, and OneDrive details.
| Requirement |
Description |
Reference |
| Read access to the site |
Required to list users. Site Owner to add users. |
SharePoint admin roles |
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_secret(
"contoso.onmicrosoft.com", "client_id", "client_secret"
)
# Get current user
me = ctx.web.current_user.get().execute_query()
print(f"Hello, {me.title} ({me.login_name})")
# List all site users
users = ctx.web.site_users.get().execute_query()
for u in users:
print(f" {u.title} ({u.login_name})")