0
votes

I have got my access token but I am struggling to see how you then send the request for the data required. In the example Call Microsoft Graph they have:

GET https://graph.microsoft.com/v1.0/me/messages?$select=subject,from,receivedDateTime&$top=25&$orderby=receivedDateTime%20DESC Accept: application/json Authorization: Bearer token

But what is the method for parsing the Accept: and the Authorization: to Microsoft Graph?

I have tried as a POST but it says bearer token empty.

$token=$_SESSION['$token'];

$url = 'https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2018-02-08T18:29:54.171Z&enddatetime=2018-02-15T18:29:54.171Z';

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
        Authorization => 'Bearer ' . $token,
        Content-Type => 'application/json'
    )
    )
);

$resp = curl_exec($curl);
curl_close($curl);
1
have you seen the ADAL libraries from MS? Lots of examples of how to call the graph API github.com/AzureADcodebrane
Not 100% familiar with CURL, but the "Authorization" "Bearer XxYyZy" should be a header, not within the posted fields.Mats Magnem

1 Answers

0
votes

Use the provided graphServiceClient

// Create Microsoft Graph client.
                try
                {
                    graphClient = new GraphServiceClient(
                        "https://graph.microsoft.com/v1.0",
                        new DelegateAuthenticationProvider(
                            async (requestMessage) =>
                            {
                                var token = await GetTokenForUserAsync();
                                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);


                            }));
                    return graphClient;
                }

Use that to authenticate your request.

$request = 'https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2018-02-08T18:29:54.171Z&enddatetime=2018-02-15T18:29:54.171Z';
hrm = new HttpRequestMessage(HttpMethod.Get, request);
            // Authenticate (add access token) our HttpRequestMessage
            await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);
            // Send the request and get the response.
            response = await graphClient.HttpProvider.SendAsync(hrm);
            jsonString = await response.Content.ReadAsStringAsync();