Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Sharepoint connection with wrong references / error message with client id instead of app id

Open rfuehrer opened this issue 3 months ago • 1 comments

I receive the following error message when I use the code (at position .execute_query() ) below:

AADSTS700016: Application with identifier 'dddddddd-3dd4-4722-8125-dddddddddddd' was not found in the directory ...

It is apparent that the client ID is being displayed as the application ID in the error message. It seems that the client ID and application ID are not being set correctly in the library. Alternatively, the error message might be misleading, but using the actual application ID, I can find the application via https://portal.azure.com/#home.

What can I do to make the code work?

Based on: https://github.com/vgrem/office365-rest-python-client/blob/master/examples/sharepoint/files/versions/list.py

from office365.azure_env import AzureEnvironment
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.auth.authentication_context import AuthenticationContext

team_site_url = "https://AAAAAA.sharepoint.com/sites/BBBBBB"
app_id = "cccccccc-a42c-4666-a482-cccccccccccc"
client_id = "dddddddd-3dd4-4722-8125-dddddddddddd"
client_secret = "eeeee~hdMX3CyaGMeeeeeeeeomQ6Y8jG5dtP_bAh"

client_credentials = ClientCredential(client_id, client_secret)
file_url = "ffffffff.pdf?csf=1&web=1&e=Lz4U2g"

ctx = ClientContext(team_site_url).with_credentials(client_credentials)

"""
Retrieves versions of the file
"""
file_with_versions = (
    ctx.web.get_file_by_server_relative_path(file_url)
    .expand(["Versions"])
    .get()
    .execute_query()
)

for version in file_with_versions.versions:
    # print(version.properties.get("Created"))
    print(version.version_label)

rfuehrer avatar Sep 11 '25 10:09 rfuehrer

Ok, my mistake, I misread your instructions (point 6.) to use the application ID instead of the client id. But now with URL http://{tenant}.sharepoint.com/sites/{site-name} I got (None, None, '401 Client Error: Unauthorized for url: https://{tenant}.sharepoint.com/sites/{site-name}/_api/contextInfo')

Is this the right URL - I do not find any information which URL ist to be used. Can you help?

rfuehrer avatar Sep 11 '25 12:09 rfuehrer