Microsoft Graph 快速入门 FAQMicrosoft Graph quick start FAQ

此 FAQ 解答了与 Microsoft Graph 快速启动相关的问题。This FAQ answers questions related to the Microsoft Graph Quick Starts.

常规设计General design

快速启动示例展示了如何使用 Microsoft Graph。The quick start samples show you how to access the power of Microsoft Graph. 在这些示例中,只需通过一次身份验证即可访问两项服务:Microsoft 帐户和 Outlook。These samples access two services with one authentication: Microsoft account and Outlook. 每个快速启动均均会访问 Microsoft 帐户用户个人资料中的信息,并显示其日历中的事件。Each quick start accesses information from Microsoft account users' profiles and displays events from their calendar.

快速启动分为四步:The quick starts involve four steps:

  • 选择平台Select your platform
  • 获取应用 ID(客户端 ID)Get your app ID (client ID)
  • 生成示例Build the sample
  • 登录,然后查看日历上的事件Sign in, and view events on your calendar

完成快速启动后,即表示应用程序可供运行。When you complete the quick start, you have an app that's ready to run.

先决条件Prerequisites

所有快速启动示例都需要访问 Outlook.com 上的邮箱的个人 Microsoft 帐户,或使用 Exchange Online 邮箱的 Microsoft 工作或学校帐户。All quick start samples require access to either a personal Microsoft account with a mailbox on Outlook.com, or a Microsoft work or school account with an Exchange Online mailbox. 如果你没有 Microsoft 帐户,可以使用以下几种方法获取免费帐户:If you don't have a Microsoft account, there are a couple of options to get a free account:

快速启动示例常见问题General quick start sample questions

此部分解答了快速启动示例的内容方面的问题。This section answers questions about the contents of the quick start samples.

不通过快速启动页面下载可以获取快速启动代码吗?Can I get the quick start code without downloading through the quick start page?

当然可以!Absolutely! 每个快速启动下载都是基于 Microsoft Graph 教程,因此,可以通过其他两种方法获取相同的源代码:Each quick start download is based on a Microsoft Graph tutorial, so you have two other options to get the same source code:

  • 按分步教程操作,自己构建代码。Build the code yourself by following the step-by-step tutorial.
  • 从相应的 GitHub 存储库下载完整的项目,然后按照自述文件中的说明配置和运行示例。Download the completed project from the corresponding GitHub repository and follow the instructions in the README to configure and run the sample.

教程和 GitHub 存储库Tutorials and GitHub repositories

下表列出了每个快速启动示例对应的教程和 GitHub 存储库。The following table lists the corresponding tutorial and GitHub repository for each quick start sample.

快速启动Quick start 教程Tutorial GitHub 存储库GitHub repository
AndroidAndroid 教程Tutorial GitHubGitHub
AngularAngular 教程Tutorial GitHubGitHub
ASP.NET MVCASP.NET MVC 教程Tutorial GitHubGitHub
iOS SwiftiOS Swift 教程Tutorial GitHubGitHub
iOS Objective-CiOS Objective-C 教程Tutorial GitHubGitHub
Node.jsNode.js 教程Tutorial GitHubGitHub
PHPPHP 教程Tutorial GitHubGitHub
PythonPython 教程Tutorial GitHubGitHub
ReactReact 教程Tutorial GitHubGitHub
RubyRuby 教程Tutorial GitHubGitHub
UWPUWP 教程Tutorial GitHubGitHub
XamarinXamarin 教程Tutorial GitHubGitHub

为什么所有快速启动示例都没有展示高级身份验证用例?Why don't any of the quick start samples show advanced authentication use cases?

通过快速启动示例,大家认识了身份验证和 Microsoft Graph API 调用。The quick start samples give you an introduction to authentication and Microsoft Graph API calls. 可以在 Azure Active Directory 文档中了解与其他身份验证流相关的更多信息。You can learn more about other authentication flows in the Azure Active Directory documentation.

使用快速启动时发生意外错误或遇到问题,该怎么办?What if I run into an unexpected error or problem with a quick start?

如果无法正常使用快速启动,请在对应的 GitHub 存储库中报告问题。If you have trouble getting the quick start to work properly, please open an issue on the corresponding GitHub repository.

已知问题Known issues

ASP.NET 快速启动在运行时显示错误:找不到部分路径“[...]\Graph Tutorial\graph-tutorial\bin\roslyn\csc.exe”。ASP.NET quick start displays an error when running it: Cannot find a part of the path '[...]\Graph Tutorial\graph-tutorial\bin\roslyn\csc.exe'.

这是由 Visual Studio 和 Roslyn 编译器的问题引起的。This is caused by an issue with Visual Studio and the Roslyn compiler. 以下选项之一应该可解决该错误。One of the following options should resolve the error.

  • 在解决方案资源管理器中卸载/重新加载项目Unload/reload project in Solution Explorer
  • 清理/重新构建解决方案Clean/Rebuild solution
  • 升级 NuGet 包Upgrade NuGet packages

运行快速启动时,我遇到错误“AADSTS50011:请求中指定的回复 URL 与为应用程序配置的回复 URL 不匹配”。I'm getting "AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application" when running a quick start.

这表示快速启动的应用程序注册存在问题。This indicates a problem with the application registration for the quick start. Microsoft Graph 快速入门页面下载快速启动时,我们会为你创建应用程序注册,并配置与示例项目使用的默认 URL 匹配的回复 URL(也称为重定向 URL)。When you download a quick start from the Microsoft Graph Quick Starts page, we create the application registration for you, and configure a reply URL (also known as a redirect URL) that matches the default URL used by the sample project. 如果你更改了此 URL,则应用程序注册将不再匹配,并可能导致此错误。If you change the URL, the app registration will no longer match and could cause this error. 若要解决此错误,请参阅快速启动项目附带的 README.md 文件,以获取有关如何创建应用程序注册并在示例代码中对其进行配置的说明。To resolve this error, consult the README.md file included with the quick start project for instructions on how to create an app registration and configure it in the sample code.

登录后,我告诉我需要管理员审批。After signing in, I'm told I need admin approval.

登录到快速启动示例之一后,您可能会看到一条消息 "需要管理员批准" XXX 教程需要只有管理员可以授予的对组织中的资源的访问权限。After signing into one of the quick start samples, you may see a message that says Need admin approval "XXX Tutorial needs permission to access resources in your organization that only an admin can grant. 请让管理员向此应用授予权限,然后才能使用它。 "Please ask an admin to grant permission to this app before you can use it." 这不是示例中的错误!This isn't a bug with the sample! 任何快速启动请求都不会请求默认情况下需要管理员同意的任何 Graph 权限范围。None of the quick starts request any Graph permission scopes that by default require admin consent. 租户管理员可以禁用您同意为尚未批准的任何应用程序的关系图权限范围的能力。Tenant administrators can disable your ability to consent to Graph permissions scopes for any apps that they have not approved. 在这种情况下,您会看到此错误。In that case, you'll see this error.

你需要与管理员合作以获得批准、使用个人 Microsoft 帐户(Outlook.com)或使用 Exchange Online 测试 Microsoft 365 租户。You'll need to work with your administrators to get approval, use a personal Microsoft account (Outlook.com), or use a test Microsoft 365 tenant with Exchange Online.

找不到需要的内容?Didn't find what you need?

如果此 FAQ 无法解答在使用一个或多个快速启动时遇到的问题,请使用下面的“反馈”**** 部分告知我们。If this FAQ didn't address a question or problem you encountered with one or more of the quick starts, please let us know using the Feedback section below.