首页 文章

REST调用Microsoft Graph

提问于
浏览
0

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

GET https://graph.microsoft.com/v1.0/me/messages?$select=subject,from,receivedDateTime&$top=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

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

相关问题