MS Graph .NET (개발자들에게 어떻게 작동하는가)
MS Graph .NET은 Microsoft Graph API와 상호작용하기 위한 데이터 액세스 도구로서 Azure Active Directory(Azure AD) 생태계의 중심 요소입니다. Microsoft Graph는 Microsoft 365의 데이터와 인텔리전스로의 게이트웨이입니다. 개발자는 다양한 Microsoft 서비스에 걸쳐 데이터를 액세스, 관리 및 분석할 수 있습니다. Microsoft Graph 클라이언트 라이브러리는 API와 쉽게 상호작용할 수 있는 일련의 메서드들을 제공하여 이 과정을 단순화합니다.
IronPDF는 .NET 애플리케이션에서 PDF 문서를 생성하기 위한 라이브러리입니다. HTML을 PDF로 변환하므로 자동으로 보고서, 청구서 및 문서를 생성하는 데 유용합니다. IronPDF는 .NET 애플리케이션과 잘 작동하여 PDF 생성을 위한 간단한 접근 방식을 제공합니다.
MS Graph .NET과 IronPDF를 결합하면 개발자가 Microsoft 365 데이터를 조작하고 PDF 문서를 생성할 수 있는 응용 프로그램을 만들 수 있습니다. 이 조합은 Microsoft 서비스에서 데이터를 필요로 하며 그 데이터를 표준 문서 형식으로 제시할 필요가 있는 비즈니스 애플리케이션을 개발하는 데 강력합니다.
MS Graph .NET 시작하기
MS Graph .NET을 .NET 프로젝트에 설정하기
특히 .NET Core 프로젝트에서 사용자 ID를 다룰 때 MS Graph .NET을 효과적으로 사용하려면 .NET 프로젝트를 설정하는 것이 첫 번째 단계입니다. 단계는 다음과 같습니다:
- NuGet 패키지 관리자를 엽니다.
- Microsoft.Graph를 검색합니다.
- Microsoft.Graph 패키지를 설치합니다.

이 과정은 프로젝트에 MS Graph .NET을 추가합니다. 이제 코딩을 시작할 준비가 되었습니다.
기본 코드 예제
현재 사용자의 프로필 정보를 검색하려고 한다고 가정해봅시다. 여기 간단한 코드 예제가 있습니다:
// Required namespaces
using Azure.Identity;
using Microsoft.Graph;
// Defining necessary credentials and scope
var clientId = "Your_Application_Id";
var tenantId = "Your_Tenant_Id";
var clientSecret = "Your_Client_Secret";
var scopes = new[] { "User.Read" };
// Configuring TokenCredentialOptions for Azure Public Cloud
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// Authenticating using client credentials
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
// Creating a new instance of GraphServiceClient
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
// Fetching current user's profile information
var user = await graphClient.Me
.Request()
.GetAsync();
// Printing user's display name
Console.WriteLine($"Hello, {user.DisplayName}!");
// Required namespaces
using Azure.Identity;
using Microsoft.Graph;
// Defining necessary credentials and scope
var clientId = "Your_Application_Id";
var tenantId = "Your_Tenant_Id";
var clientSecret = "Your_Client_Secret";
var scopes = new[] { "User.Read" };
// Configuring TokenCredentialOptions for Azure Public Cloud
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// Authenticating using client credentials
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
// Creating a new instance of GraphServiceClient
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
// Fetching current user's profile information
var user = await graphClient.Me
.Request()
.GetAsync();
// Printing user's display name
Console.WriteLine($"Hello, {user.DisplayName}!");
' Required namespaces
Imports Azure.Identity
Imports Microsoft.Graph
' Defining necessary credentials and scope
Private clientId = "Your_Application_Id"
Private tenantId = "Your_Tenant_Id"
Private clientSecret = "Your_Client_Secret"
Private scopes = { "User.Read" }
' Configuring TokenCredentialOptions for Azure Public Cloud
Private options = New TokenCredentialOptions With {.AuthorityHost = AzureAuthorityHosts.AzurePublicCloud}
' Authenticating using client credentials
Private clientSecretCredential = New ClientSecretCredential(tenantId, clientId, clientSecret, options)
' Creating a new instance of GraphServiceClient
Private graphClient = New GraphServiceClient(clientSecretCredential, scopes)
' Fetching current user's profile information
Private user = await graphClient.Me.Request().GetAsync()
' Printing user's display name
Console.WriteLine($"Hello, {user.DisplayName}!")
이 코드 스니펫은 Azure AD 인증을 위한 클라이언트 비밀을 활용하여 GraphServiceClient의 새 인스턴스를 만드는 방법을 보여줍니다. 클라이언트 자격 증명을 사용하여 인증합니다. 그런 다음 현재 사용자의 표시 이름을 검색합니다. 이후 MS Graph .NET과 인증 공급자 구성을 프로젝트에 추가했는지 확인하십시오.
MS Graph .NET의 기능
사용자 이메일 검색
사용자의 Microsoft 계정 메일박스에서 이메일을 검색하려면 Mail.Read 권한을 사용합니다. 가장 최근의 이메일을 나열하는 방법은 다음과 같습니다:
// Retrieving the top 10 messages from the user's mailbox
var messages = await graphClient.Me.Messages
.Request()
.Top(10)
.GetAsync();
// Iterating through the messages and printing their subjects
foreach (var message in messages)
{
Console.WriteLine($"Subject: {message.Subject}");
}
// Retrieving the top 10 messages from the user's mailbox
var messages = await graphClient.Me.Messages
.Request()
.Top(10)
.GetAsync();
// Iterating through the messages and printing their subjects
foreach (var message in messages)
{
Console.WriteLine($"Subject: {message.Subject}");
}
' Retrieving the top 10 messages from the user's mailbox
Dim messages = Await graphClient.Me.Messages.Request().Top(10).GetAsync()
' Iterating through the messages and printing their subjects
For Each message In messages
Console.WriteLine($"Subject: {message.Subject}")
Next message
이 코드는 사용자의 받은 편지함 상위 10개의 이메일 제목을 나열합니다.
이메일 보내기
이메일 보내기는 Message 객체를 생성하고 보내는 것을 포함합니다:
// Creating a message to be sent
var message = new Message
{
Subject = "Hello from MS Graph .NET",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Hello, this is a test email."
},
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "recipient@example.com"
}
}
}
};
// Sending the email
await graphClient.Me.SendMail(message, null)
.Request()
.PostAsync();
// Creating a message to be sent
var message = new Message
{
Subject = "Hello from MS Graph .NET",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "Hello, this is a test email."
},
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "recipient@example.com"
}
}
}
};
// Sending the email
await graphClient.Me.SendMail(message, null)
.Request()
.PostAsync();
' Creating a message to be sent
Dim message As New Message With {
.Subject = "Hello from MS Graph .NET",
.Body = New ItemBody With {
.ContentType = BodyType.Text,
.Content = "Hello, this is a test email."
},
.ToRecipients = New List(Of Recipient)() From {
New Recipient With {
.EmailAddress = New EmailAddress With {.Address = "recipient@example.com"}
}
}
}
' Sending the email
Await graphClient.Me.SendMail(message, Nothing).Request().PostAsync()
간단한 텍스트 본문과 함께 이메일을 보냅니다.
캘린더 이벤트 관리
사용자의 캘린더에 이벤트를 추가하려면:
// Creating a calendar event
var @event = new Event
{
Subject = "Team Meeting",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Discuss project updates."
},
Start = new DateTimeTimeZone
{
DateTime = "2024-04-15T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2024-04-15T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Conference Room 1"
}
};
// Adding the event to the user's calendar
await graphClient.Me.Events
.Request()
.AddAsync(@event);
// Creating a calendar event
var @event = new Event
{
Subject = "Team Meeting",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Discuss project updates."
},
Start = new DateTimeTimeZone
{
DateTime = "2024-04-15T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2024-04-15T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Conference Room 1"
}
};
// Adding the event to the user's calendar
await graphClient.Me.Events
.Request()
.AddAsync(@event);
' Creating a calendar event
Dim [event] As [Event] = New [Event] With {
.Subject = "Team Meeting",
.Body = New ItemBody With {
.ContentType = BodyType.Html,
.Content = "Discuss project updates."
},
.Start = New DateTimeTimeZone With {
.DateTime = "2024-04-15T12:00:00",
.TimeZone = "Pacific Standard Time"
},
.End = New DateTimeTimeZone With {
.DateTime = "2024-04-15T14:00:00",
.TimeZone = "Pacific Standard Time"
},
.Location = New Location With {.DisplayName = "Conference Room 1"}
}
' Adding the event to the user's calendar
Await graphClient.Me.Events.Request().AddAsync([event])
이 코드는 캘린더에 새로운 이벤트를 일정 잡습니다.
OneDrive 파일 접근
사용자 OneDrive의 루트에서 파일을 나열하려면:
// Retrieving files from the root OneDrive folder
var files = await graphClient.Me.Drive.Root.Children
.Request()
.GetAsync();
// Printing each file's name
foreach (var file in files)
{
Console.WriteLine(file.Name);
}
// Retrieving files from the root OneDrive folder
var files = await graphClient.Me.Drive.Root.Children
.Request()
.GetAsync();
// Printing each file's name
foreach (var file in files)
{
Console.WriteLine(file.Name);
}
' Retrieving files from the root OneDrive folder
Dim files = Await graphClient.Me.Drive.Root.Children.Request().GetAsync()
' Printing each file's name
For Each file In files
Console.WriteLine(file.Name)
Next file
이 코드는 OneDrive 루트 디렉토리의 파일 이름을 출력합니다.
Teams와 함께 작업하기
사용자가 속한 팀 목록을 검색하려면:
// Retrieving teams that the user is part of
var teams = await graphClient.Me.JoinedTeams
.Request()
.GetAsync();
// Printing each team's display name
foreach (var team in teams)
{
Console.WriteLine($"Team name: {team.DisplayName}");
}
// Retrieving teams that the user is part of
var teams = await graphClient.Me.JoinedTeams
.Request()
.GetAsync();
// Printing each team's display name
foreach (var team in teams)
{
Console.WriteLine($"Team name: {team.DisplayName}");
}
' Retrieving teams that the user is part of
Dim teams = Await graphClient.Me.JoinedTeams.Request().GetAsync()
' Printing each team's display name
For Each team In teams
Console.WriteLine($"Team name: {team.DisplayName}")
Next team
이 코드는 사용자가 속한 팀의 이름을 나열합니다.
각각의 이러한 기능은 MS Graph .NET의 강력함과 다재다능함을 보여줍니다. 그들은 Microsoft 365 서비스를 애플리케이션에 통합하는 방법을 보여줍니다.
MS Graph .NET과 IronPDF 통합

.NET 애플리케이션에서 PDF와 작업하려는 경우 .NET 개발자를 위한 IronPDF 라이브러리가 확실한 선택입니다. 이는 라이브러리로, 추가 외부 PDF 도구나 소프트웨어 없이 애플리케이션이 PDF 파일을 읽고 생성하며 조작할 수 있도록 합니다.
사용 사례: IronPDF와 MS Graph .NET 통합
Microsoft 365에서 문서, 예를 들어 보고서나 청구서를 가져와 PDF로 변환해야 하는 애플리케이션을 구축한다고 상상해보십시오. MS Graph .NET은 OneDrive나 SharePoint에 저장된 파일을 포함하여 Microsoft 365 리소스와 상호작용할 수 있도록 합니다. 그 후 IronPDF를 사용하여 이러한 문서를 PDF로 변환할 수 있습니다. 이 조합은 특히 자동 보고서 생성이나 이메일 및 첨부 파일을 PDF 형식으로 아카이빙하여 쉽게 배포하는 데 유용합니다.
코드 예제: MS Graph에서 PDF로
간단한 예제를 살펴보겠습니다. MS Graph .NET을 사용하여 OneDrive에서 문서를 가져온 다음 IronPDF를 사용하여 해당 문서를 PDF로 변환합니다. MSGraph 인증을 이미 설정했다고 가정하겠습니다. 그렇지 않다면, Microsoft 사이트에 시작하는 데 도움이 될 많은 문서가 있습니다.
// Simplified example, ensure to handle exceptions and errors appropriately.
using Microsoft.Graph;
using IronPdf;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Setting up the GraphServiceClient with a DelegateAuthenticationProvider
var graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
// Insert code to acquire token
string accessToken = await GetAccessTokenAsync();
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
}));
// Replace 'itemId' with the ID of your document in OneDrive
var stream = await graphClient.Me.Drive.Items["itemId"].Content.Request().GetAsync();
// IronPDF setup to convert the fetched file to PDF
var renderer = new HtmlToPdf();
var pdfDocument = renderer.RenderHtmlAsPdf(StreamToString(stream));
// Save the PDF to a file
pdfDocument.SaveAs("YourDocument.pdf");
}
// Method to convert a Stream to a String
static string StreamToString(Stream stream)
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
// Method to obtain the access token
static async Task<string> GetAccessTokenAsync()
{
// Implement your authentication logic here to return the access token
return "your_access_token";
}
}
// Simplified example, ensure to handle exceptions and errors appropriately.
using Microsoft.Graph;
using IronPdf;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Setting up the GraphServiceClient with a DelegateAuthenticationProvider
var graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
// Insert code to acquire token
string accessToken = await GetAccessTokenAsync();
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
}));
// Replace 'itemId' with the ID of your document in OneDrive
var stream = await graphClient.Me.Drive.Items["itemId"].Content.Request().GetAsync();
// IronPDF setup to convert the fetched file to PDF
var renderer = new HtmlToPdf();
var pdfDocument = renderer.RenderHtmlAsPdf(StreamToString(stream));
// Save the PDF to a file
pdfDocument.SaveAs("YourDocument.pdf");
}
// Method to convert a Stream to a String
static string StreamToString(Stream stream)
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
// Method to obtain the access token
static async Task<string> GetAccessTokenAsync()
{
// Implement your authentication logic here to return the access token
return "your_access_token";
}
}
' Simplified example, ensure to handle exceptions and errors appropriately.
Imports Microsoft.Graph
Imports IronPdf
Imports System.IO
Imports System.Threading.Tasks
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
' Setting up the GraphServiceClient with a DelegateAuthenticationProvider
Dim graphClient = New GraphServiceClient(New DelegateAuthenticationProvider(Async Sub(requestMessage)
' Insert code to acquire token
Dim accessToken As String = Await GetAccessTokenAsync()
requestMessage.Headers.Authorization = New System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken)
End Sub))
' Replace 'itemId' with the ID of your document in OneDrive
Dim stream = Await graphClient.Me.Drive.Items("itemId").Content.Request().GetAsync()
' IronPDF setup to convert the fetched file to PDF
Dim renderer = New HtmlToPdf()
Dim pdfDocument = renderer.RenderHtmlAsPdf(StreamToString(stream))
' Save the PDF to a file
pdfDocument.SaveAs("YourDocument.pdf")
End Function
' Method to convert a Stream to a String
Private Shared Function StreamToString(ByVal stream As Stream) As String
Using reader = New StreamReader(stream)
Return reader.ReadToEnd()
End Using
End Function
' Method to obtain the access token
Private Shared Async Function GetAccessTokenAsync() As Task(Of String)
' Implement your authentication logic here to return the access token
Return "your_access_token"
End Function
End Class
이 코드에서 주목할 만한 몇 가지 사항:
- OneDrive에 저장된 파일에 액세스하기 위해 MSGraph를 사용합니다. 이를 위해 항목의 ID가 필요하며 Graph API를 통해 얻을 수 있습니다.
- 이 예에서는 파일 스트림을 문자열로 변환합니다. HTML 문서에 잘 작동합니다. 바이너리 파일(예: Word 문서)을 처리하는 경우에는 다른 방법을 사용하여 이러한 파일을 PDF로 변환해야 합니다.
- IronPDF의 RenderHtmlAsPdf 메소드를 사용하여 HTML 문자열에서 PDF를 생성합니다. 소스 문서가 HTML이 아닌 경우에도 IronPDF는 다른 형식으로 작업할 수 있는 방법을 제공합니다.
이것은 단순화된 예제라는 점을 기억하세요. 실제 애플리케이션에서는 인증을 보다 안정적으로 처리하고, 오류를 관리하며, 다수의 파일 형식을 더 우아하게 처리해야 할 것입니다. 하지만 이것은 .NET 프로젝트에서 MSGraph와 IronPDF를 통합하기 위한 좋은 출발점이 될 것입니다.
결론

C# 애플리케이션에 Microsoft 365 기능을 통합하려는 개발자에게 MS Graph .NET SDK는 필수 도구입니다. 먼저 MS Graph .NET SDK 라이선스 및 가격 정보를 $799에서 시작하여 탐색하십시오.
자주 묻는 질문
MS Graph .NET이 개발자가 Microsoft 365 데이터를 액세스하는 데 어떻게 도움을 주나요?
MS Graph .NET은 개발자가 Microsoft Graph API를 통해 Microsoft 365 데이터를 액세스하고 관리할 수 있도록 하는 게이트웨이 역할을 하며, 이는 Azure Active Directory 생태계의 일부입니다. 데이터 상호작용 프로세스를 간소화하는 방법을 제공합니다.
Microsoft 365 데이터를 사용하여 .NET에서 PDF 문서를 개발자가 어떻게 생성할 수 있나요?
개발자는 IronPDF를 사용하여 .NET 응용 프로그램에서 PDF 문서를 생성할 수 있으며, MS Graph .NET을 통해 액세스한 데이터를 활용하여 HTML 및 다른 문서 형식을 PDF로 변환할 수 있습니다.
프로젝트에서 MS Graph .NET을 사용하기 시작하려면 무엇이 필요합니까?
MS Graph .NET을 사용하려면 NuGet 패키지 관리자를 통해 Microsoft.Graph 패키지를 설치하고 Microsoft 365 서비스와 상호 작용하기 위해 클라이언트 자격 증명을 사용한 인증을 설정해야 합니다.
개발자가 MS Graph .NET을 사용하여 이메일을 보내려면 어떻게 해야 합니까?
개발자는 원하는 내용과 수신자 정보를 포함하는 `Message` 객체를 생성한 다음 `GraphServiceClient`의 `SendMail` 메서드를 활용하여 MS Graph .NET을 사용하여 이메일을 보낼 수 있습니다.
MS Graph .NET은 Microsoft 365 계정에서 일정 이벤트를 관리할 수 있습니까?
네, MS Graph .NET은 `Event` 객체를 생성하고 `Me.Events.Request().AddAsync(event)`와 같은 메서드를 사용하여 사용자의 일정에 이벤트를 추가하여 일정 이벤트를 관리할 수 있습니다.
OneDrive 문서를 .NET 응용 프로그램에서 PDF로 변환하려면 어떻게 해야 합니까?
OneDrive 문서를 PDF로 변환하려면 MS Graph .NET을 사용하여 문서를 가져온 다음 IronPDF를 사용하여 문서 내용을 PDF 형식으로 변환할 수 있습니다.
MS Graph .NET과 IronPDF를 통합할 때 고려해야 할 사항은 무엇입니까?
MS Graph .NET과 IronPDF를 통합할 때는 강력한 인증, 오류 처리 및 다양한 파일 형식의 호환성을 고려하여 원활한 변환 및 데이터 관리를 보장해야 합니다.
MS Graph .NET과 IronPDF를 함께 사용했을 때의 실제 응용 프로그램 사례는 무엇입니까?
MS Graph .NET과 IronPDF를 함께 사용하면 PDF 보고서 생성, 이메일을 PDF로 아카이브, Microsoft 365 데이터를 사용하여 표준화된 비즈니스 문서를 생성하는 등의 응용 프로그램을 사용할 수 있습니다.
MS Graph .NET은 .NET 응용 프로그램의 효율성을 어떻게 향상시킬 수 있습니까?
MS Graph .NET은 Microsoft 365 서비스에 대한 간소화된 액세스를 제공하여 개발자가 최소한의 코드로 데이터를 검색, 관리 및 조작할 수 있게 함으로써 생산성과 응용 프로그램 기능을 향상시킵니다.




