跳到正文
Skillpedia
API 与服务器(后端)40k · #7298

msgraph-sdk

它能做什么

这个工具可以帮助开发者将程序与 Microsoft 365 中的数据连接起来,比如邮件、日历和文件。它简化了身份验证以及对 Microsoft 服务接口的调用。

适用场景

  • ✓当你开发的应用需要读取某个账户中的邮件时。
  • ✓当你开发的程序需要在日历中安排会议时。
  • ✓当你要构建一个管理 OneDrive 或 SharePoint 中文件的系统时。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/msgraph-sdk/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我该如何将我的 Python 应用连接到 Microsoft 365 中的用户数据?”

每周 5 个新技能,1 分钟读完。

工作原理

该程序使用一个“SDK”(软件开发工具包,即一组预先构建好的工具)来与 Microsoft 服务通信。它负责处理安全问题(谁可以访问哪些数据),以及获取或修改数据的请求。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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

…

常见问题

什么是 Microsoft Graph?

它是访问 Microsoft 365 数据和服务的入口,例如用户、邮件、日历和文件。

什么是 SDK?

SDK 即软件开发工具包,是一组能让你更轻松地开发与特定服务交互的程序的工具。这里指的就是 Microsoft Graph。

为什么需要关心身份验证?

身份验证可以确保只有经过授权的用户或应用才能访问数据,从而保护敏感信息。

详情

作者的原始描述

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

热度

GitHub 星标
40k
排名
#7298
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能