lidholm
lidholm

Reputation: 21

Getting the resource schedule from Office 365?

I had a python script which could get fetch the schedule for a resource(room) from the company's Office 365 calendar by calling https://outlook.office365.com/api/v1.0/users/<[email protected]>/calendarview?startDateTime=2016-08-07 22:00:00&endDateTime=2016-08-08 22:00:00

This doesn't seem to work anymore? As far as I could find out it looks like the API has changed by restricting the permissions to resource calendar. Is that a correct assumption or am I doing something wrong?

Is there a way to actually get the schedule for a resource?

I would preferably want to do this in Python or C#

Upvotes: 0

Views: 377

Answers (1)

Fei Xue
Fei Xue

Reputation: 14649

What's the error message you get? If you were getting the error like The access token is acquired using an authentication method that is too weak to allow access for this application, we need to use the certificate make to request the token instead of using the client id and secret.

Here is an code sample that use the certificate to request the token for your reference:

 public static async Task<string> GetTokenByCert(string clientId, string tenant, string certThumbprint,string resource)
    {
        string authority = $"https://login.windows.net/{tenant}";

        X509Certificate2 cert = CertHelper.FindCert(certThumbprint);
        var certCred = new ClientAssertionCertificate(clientId, cert);
        var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority);
        AuthenticationResult result = null;
        try
        {
            result = await authContext.AcquireTokenAsync(resource, certCred);
        }
        catch (Exception ex)
        {
        }

        return result.AccessToken;
    }

More detail about config/use the certificate to request the token, please refer here.

Upvotes: 0

Related Questions