对 Microsoft Graph 的 REST 调用 [英] REST call to Microsoft Graph

查看:51
本文介绍了对 Microsoft Graph 的 REST 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的访问令牌,但我正在努力了解您如何发送所需数据的请求.在示例 调用 Microsoft Graph 中,他们有:

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:

获取https://graph.microsoft.com/v1.0/me/messages?$select=subject,from,receivedDateTime&$top=25&$orderby=receivedDateTime%20DESC接受:application/json 授权:不记名令牌

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

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

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

我尝试过 POST 但它说不记名令牌为空.

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

推荐答案

使用提供的 graphServiceClient

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

这篇关于对 Microsoft Graph 的 REST 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆