Hi @Pavan Goud
The access /me/contacts
endpoint does not support the use of the client credential flow, which requires user participation to access, and the client credential flow does not have user participation, so please use auth code flow to access on behalf of the user, and use the delegation permissions Contacts.Read or Contacts.ReadWrite.
Refer to the code below.
scopes = ['User.Read']
# Multi-tenant apps can use "common",
# single-tenant apps must use the tenant ID from the Azure portal
tenant_id = 'common'
# Values from app registration
client_id = 'YOUR_CLIENT_ID'
client_secret = 'YOUR_CLIENT_SECRET'
redirect_uri = 'YOUR_REDIRECT_URI'
# For authorization code flow, the user signs into the Microsoft
# identity platform, and the browser is redirected back to your app
# with an authorization code in the query parameters
authorization_code = 'AUTH_CODE_FROM_REDIRECT'
# azure.identity.aio
credential = AuthorizationCodeCredential(
tenant_id=tenant_id,
client_id=client_id,
authorization_code=authorization_code,
redirect_uri=redirect_uri,
client_secret=client_secret)
graph_client = GraphServiceClient(credential, scopes) # type: ignore
More details can be found at this link:
https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=python#authorization-code-provider
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.