Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)40k · #7298

msgraph-sdk

Skill này làm gì

Công cụ này giúp lập trình viên kết nối chương trình của họ với dữ liệu Microsoft 365 như email, lịch và tệp. Nó đơn giản hóa việc xác thực và gọi các hàm của Microsoft.

Khi nào nên dùng

  • ✓Khi bạn xây dựng ứng dụng cần đọc email từ một tài khoản.
  • ✓Khi bạn phát triển chương trình lên lịch họp trong lịch.
  • ✓Khi bạn tạo hệ thống quản lý tệp trên OneDrive hoặc SharePoint.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/msgraph-sdk/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/msgraph-sdk/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để kết nối ứng dụng Python của tôi với dữ liệu người dùng trong Microsoft 365?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Chương trình dùng một 'SDK', tức bộ công cụ dựng sẵn, để giao tiếp với các dịch vụ của Microsoft. Nó xử lý phần bảo mật (ai được truy cập gì) và các yêu cầu để lấy hoặc thay đổi dữ liệu.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Microsoft Graph SDK

Use this skill when integrating Microsoft Graph into an application to access Microsoft 365 data and services.

Always ground implementation in the current Microsoft Graph SDK documentation and SDK version for the target language rather than relying on memory alone.

Determine the target language first

  1. Use the .NET workflow when the project contains .cs, .csproj, or .sln files, or when the user asks for C# guidance. Follow references/dotnet.md.
  2. Use the TypeScript / JavaScript workflow when the project contains package.json, .ts, or .js files, or when the user asks for Node.js / browser guidance. Follow references/typescript.md.
  3. Use the Python workflow when the project contains .py, pyproject.toml, or requirements.txt, or when the user asks for Python guidance. Follow references/python.md.
  4. If multiple languages are present, match the language of the files being edited or ask the user.

Always consult live documentation

Authentication — choose the right pattern

Selecting the wrong auth flow is the most common Graph integration mistake. Apply this decision tree before writing any auth code:

Scenario Flow to use
Background service / daemon with no user Client credentials (app-only)
Agent or API acting on behalf of a signed-in user On-Behalf-Of (OBO)
App running in Azure (Function, Container App, VM) Managed Identity (preferred over secrets)
CLI tool or local dev script Device code or interactive browser
Single-page app (browser only) Authorization code + PKCE
  • Never use client credentials when a user context is required — Graph enforces this at the permission level (application vs. delegated).
  • Prefer DefaultAzureCredential in Azure-hosted apps; it tries managed identity first and falls back gracefully for local dev.
  • Never hardcode secrets. Use environment variables, Azure Key Vault, or the Secret Manager.

Core SDK usage patterns

Building the client

Always construct GraphServiceClient once and reuse it (it manages token caching internally).

Pass a credential from the Azure Identity library — never build raw HTTP clients manually.

Making calls

  • Use the fluent builder API: client.Users[userId].Messages.GetAsync(...).
  • Always await async calls.
  • Specify $select to limit returned fields — Graph returns large default payloads.
  • Use $filter server-side rather than filtering returned collections in memory.
  • Use $expand to fetch related resources in a single call when relationships are small.

Pagination

Graph paginates collections. Never assume all items arrive in one response:

  • Check for an @odata.nextLink on the response.
  • Use the SDK's PageIterator helper (available in all three SDKs) to walk pages automatically.
  • Set $top to control page size (max varies by resource, typically 999).

Advanced patterns

Batch requests

Combine up to 20 independent Graph calls into a single HTTP request using the $batch endpoint. Use batching when:

  • Initializing data for a dashboard or agent that needs multiple resources upfront.
  • Reducing latency in high-call-count operations.

Batch responses arrive out of order — match them by the id field you assigned each request.

Delta queries

Use delta queries to sync changes incrementally instead of polling full collections:

  • First call: GET /users/delta returns all items + a @odata.deltaLink.
  • Subsequent calls: use the deltaLink to receive only what changed since the last sync.
  • Supported on: users, groups, messages, calendar events, Teams channels, and more.
  • Store the deltaLink durably (database, blob) between sync runs.

Change notifications (webhooks)

Subscribe to resource changes with POST /subscriptions:

  • Graph delivers change events to your HTTPS notification URL.
  • Subscriptions expire — renew them before expirationDateTime (max varies by resource; typically 1–3 days for mail/calendar, up to 4230 minutes for users/groups).

…

Câu hỏi thường gặp

Microsoft Graph là gì?

Đây là cổng truy cập dữ liệu và dịch vụ của Microsoft 365, như người dùng, thư, lịch và tệp.

SDK là gì?

SDK là Software Development Kit, một bộ công cụ giúp xây dựng chương trình tương tác với một dịch vụ cụ thể, ở đây là Microsoft Graph.

Vì sao tôi cần quan tâm đến xác thực?

Xác thực đảm bảo chỉ người dùng hoặc ứng dụng được ủy quyền mới truy cập được dữ liệu, bảo vệ thông tin nhạy cảm.

Chi tiết

Mô tả gốc của tác giả

Integrate Microsoft Graph SDK into any project — .NET, TypeScript/JavaScript, or Python. Covers auth patterns (client credentials, OBO, managed identity), SDK setup, calling Graph APIs, batching, delta queries, change notifications, throttling, and permission scopes. Use when accessing Microsoft 365 data (users, mail, calendar, Teams, files, SharePoint) from any application type.

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7298
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự