REST调用Microsoft Graph

时间:2018-02-08 19:48:19

标签: rest microsoft-graph

我有我的访问令牌,但我很难看到你如何发送所需数据的请求。在示例Call Microsoft Graph中,他们有:

  

GET   ?https://graph.microsoft.com/v1.0/me/messages $选择=受试者,从,receivedDateTime&安培; $顶部= 25安培; $的OrderBy = receivedDateTime%20DESC   接受:application / json授权:Bearer token

但解析Accept:和Authorization:to Microsoft Graph的方法是什么?

我已尝试过POST,但它表示持有人令牌为空。

$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 个答案:

答案 0 :(得分:0)

使用提供的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;
                }

使用它来验证您的请求。

$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();