安装 Microsoft Graph SDKInstall the Microsoft Graph SDKs

Microsoft Graph SDK 现已通过 Github 和常用平台包管理器包含在你的项目中。The Microsoft Graph SDKs are available to be included in your projects via GitHub and popular platform package managers. 此主题说明了如何将 Microsoft Graph SDK 安装到你的项目中。This topic describes how you can install the Microsoft Graph SDK into your project.

安装 Microsoft Graph .NET SDKInstall the Microsoft Graph .NET SDK

以下 NuGet 程序包中都包含了 Microsoft Graph .NET SDK:The Microsoft Graph .NET SDK is included in the following NuGet packages:

  • Microsoft.Graph - 包含模型和请求构建器,用于访问 v1.0 带有流畅 API 的终结点。Microsoft.Graph - Contains the models and request builders for accessing the v1.0 endpoint with the fluent API. Microsoft.Graph 在 Microsoft.Graph.Core 上有一个依赖项。Microsoft.Graph has a dependency on Microsoft.Graph.Core.
  • Microsoft.Graph.Beta - 包含模型和请求构建器,用于访问 beta 带有流畅 API 的终结点。Microsoft.Graph.Beta - Contains the models and request builders for accessing the beta endpoint with the fluent API. Microsoft.Graph.Beta 在 Microsoft.Graph.Core 上有一个依赖项。Microsoft.Graph.Beta has a dependency on Microsoft.Graph.Core.
  • Microsoft.Graph.Core - 呼叫 Microsoft Graph 的核心库。Microsoft.Graph.Core - The core library for making calls to Microsoft Graph.
  • Microsoft.Graph.Auth - 提供 Microsoft 身份验证库 (MSAL) 的基于身份验证场景包装器,可以和 Microsoft Graph SDK 配合使用。Microsoft.Graph.Auth - Provides an authentication scenario-based wrapper of the Microsoft Authentication Library (MSAL) for use with the Microsoft Graph SDK. Microsoft.Graph.Auth 依赖于 Microsoft.Graph.Core。Microsoft.Graph.Auth has a dependency on Microsoft.Graph.Core.

可以使用 Visual Studio 中的程序包管理器 UI 或程序包管理器控制台 将Microsoft.Graph 程序包安装到项目中。You can use either the Package Manager UI in Visual Studio or the Package Manager Console to install the Microsoft.Graph packages into your project. 以下程序包管理器控制台命令将安装 Microsoft.Graph、Microsoft.Graph.Core 和 Microsoft.Graph.Auth 库。The following Package Manager Console commands will install the Microsoft.Graph, Microsoft.Graph.Core, and Microsoft.Graph.Auth libraries. Microsoft.Graph.Core 依赖于 Microsoft.Graph。Microsoft.Graph.Core is installed as a dependency of Microsoft.Graph.

Install-Package Microsoft.Graph
Install-Package Microsoft.Graph.Auth -IncludePrerelease

安装 Microsoft Graph Java SDKInstall the Microsoft Graph Java SDK

以下程序包中都包含了 Microsoft Graph Java SDK:The Microsoft Graph Java SDK is included in the following packages:

  • Microsoft-Graph - 包含模型和请求构建器,用于访问 v1.0 带有流畅 API 的终结点。microsoft-graph - Contains the models and request builders for accessing the v1.0 endpoint with the fluent API.
  • Microsoft-Graph-Beta - 包含模型和请求构建器,用于访问 beta 带有流畅 API 的终结点。microsoft-graph-beta - Contains the models and request builders for accessing the beta endpoint with the fluent API.
  • Microsoft-Graph-Core - 呼叫 Microsoft Graph 的核心库。microsoft-graph-core - The core library for making calls to Microsoft Graph.
  • Microsoft-Graph-Auth - 提供 Microsoft 身份验证库 (MSAL) 的基于身份验证场景包装器,可以和 Microsoft Graph SDK 配合使用。microsoft-graph-auth - Provides an authentication scenario-based wrapper of Microsoft Authentication Library (MSAL) for use with the Microsoft Graph SDK.

通过 Gradle 安装 Microsoft Graph Java SDKInstall the Microsoft Graph Java SDK via Gradle

将存储库和 microsoft-graph 的一个编译依赖项添加到项目的 build.gradle:Add the repository and a compile dependency for microsoft-graph to your project's build.gradle:

repository {
    jcenter()
    jcenter{
        url 'https://oss.jfrog.org/artifactory/oss-snapshot-local'
    }
}

dependency {
    // Include the sdk as a dependency
    implementation 'com.microsoft.graph:microsoft-graph:2.+'
    implementation 'com.microsoft.graph:microsoft-graph-auth:0.3.0'
}

通过 Maven 安装 Microsoft Graph Java SDKInstall the Microsoft Graph Java SDK via Maven

添加存储库到 profilespom.xml 的元素中:Add the repositories in the profiles element in pom.xml:

<profiles>
    <profile>
        <repositories>
            <repository>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
                <id>bintray-microsoftgraph-Maven</id>
                <name>bintray</name>
                <url>https://dl.bintray.com/microsoftgraph/Maven</url>
            </repository>
        </repositories>
    </profile>
    <profile>
       <id>allow-snapshots</id>
          <activation><activeByDefault>true</activeByDefault></activation>
       <repositories>
         <repository>
           <id>snapshots-repo</id>
           <url>https://oss.sonatype.org/content/repositories/snapshots</url>
           <releases><enabled>false</enabled></releases>
           <snapshots><enabled>true</enabled></snapshots>
         </repository>
       </repositories>
     </profile>
</profiles>

添加依赖项到 dependenciespom.xml 的元素中:Add the dependency in the dependencies element in pom.xml:

<dependency>
    <groupId>com.microsoft.graph</groupId>
    <artifactId>microsoft-graph</artifactId>
    <version>[2.0,)</version>
</dependency>
<dependency>
    <groupId>com.microsoft.graph</groupId>
    <artifactId>microsoft-graph-auth</artifactId>
    <version>0.3.0</version>
</dependency>

安装 Microsoft Graph JavaScript SDKInstall the Microsoft Graph Javascript SDK

以下程序包中都包含了 Microsoft Graph JavaScript SDK:The Microsoft Graph Javascript SDK is included in the following packages:

  • @microsoft/microsoft-graph-client (npm) - 呼叫 Microsoft Graph 的核心库。@microsoft/microsoft-graph-client (npm)- The core library for making calls to Microsoft Graph.
  • @microsoft/microsoft-graph-types (npm) - 用于 Microsoft Graph 实体的 Typescript 类型。@microsoft/microsoft-graph-types (npm) - The Typescript types for the Microsoft Graph entities.

可以使用 npm 安装 Microsoft Graph JavaScript SDK:You can use npm to install the Microsoft Graph Javascript SDK:

npm install @microsoft/microsoft-graph-client --save
npm install @microsoft/microsoft-graph-types --save-dev

安装 Microsoft Graph Objective-C SDKInstall the Microsoft Graph Objective-C SDK

Microsoft Graph Objective-C SDK 支持 iOS 和 macOS 平台,可以通过 CocoaPod 或 Carthage 安装到项目中。The Microsoft Graph Objective-C SDK supports both iOS and macOS platforms and can be installed into your project using either CocoaPods or Carthage.

使用 Cocoapod 安装 Microsoft Graph Objective-C SDKInstall the Microsoft Graph Objective-C SDK using Cocoapods

添加 podflie 中的以下行,将 Objective-C Microsoft Graph SDK 和 Microsoft Graph Objective-C Auth SDK 安装到 xcode 项目中:Add the following line in your podfile to include the Objective-C Microsoft Graph SDK and Microsoft Graph Objective-C Auth SDK in your xcode project:

pod 'MSGraphClientSDK'
pod 'MSGraphMSALAuthProvider'

使用 Carthage 安装 Microsoft Graph Objective-C SDKInstall the Microsoft Graph Objective-C SDK using Carthage

执行以下步骤使用 Carthage 程序包管理器安装 Microsoft Graph Objective-C SDK 和 Microsoft Graph Objective-C Auth SDK。Perform the following steps to install the Microsoft Graph Objective-C SDK and Microsoft Graph Objective-C Auth SDK using the Carthage package manager.

  1. 创建 Cartfile,指定 Objective-C SDK Github 存储库 和目标的 发行标记Create a Cartfile that specifies the Objective-C SDK GitHub repository and release tag to target.

    github "microsoftgraph/msgraph-sdk-objc" "tags/<latest_release_tag>"
    github "microsoftgraph/msgraph-sdk-objc-auth" "tags/<latest_release_tag>"
    
  2. 运行 carthage updateRun carthage update. 此操作将依赖项提取到 Carthage/Checkouts 文件夹,然后生成 MSGraphClientSDK 库。This will fetch dependencies into a Carthage/Checkouts folder and then builds the MSGraphClientSDK library.

  3. 使用 Xcode,在应用程序目标的 常规 设置选项卡上的 链接的框架和库 部分,将 MSGraphClientSDK.frameworkMSGraphMSALAuthProvider.framework 从磁盘上的 Carthage/Build 文件夹拖放到此处。Using Xcode, in your application target's General settings tab, in the Linked Frameworks and Libraries section, drag and drop the MSGraphClientSDK.framework and MSGraphMSALAuthProvider.framework from the Carthage/Build folder on disk.

  4. 在应用程序目标的 生成阶段 设置选项卡上,单击 + 图标,并选择 新建运行脚本阶段On your application target's Build Phases settings tab, click the + icon and choose New Run Script Phase. 创建指定 Shell 的运行脚本(例如:/bin/sh),添加下列内容至 脚本:Create a run script in which you specify your shell (ex: /bin/sh), and add the following contents to the script:

    /usr/local/bin/carthage copy-frameworks
    
  5. 并添加路径至希望在 Input Files 下使用的框架。Add the paths to the frameworks you want to use under Input Files.

    $(SRCROOT)/Carthage/Build/iOS/MSGraphClientSDK.framework
    $(SRCROOT)/Carthage/Build/iOS/MSGraphMSALAuthProvider.framework
    

安装 Microsoft Graph PHP SDKInstall the Microsoft Graph PHP SDK

Microsoft Graph PHP SDK 已在 packagist.org 中可用,可按以下方法安装:The Microsoft Graph PHP SDK is available from packagist.org and can be installed in the following ways:

使用 composer 手动安装 Microsoft Graph PHP SDKInstall the Microsoft Graph PHP SDK manually using composer

composer require microsoft/microsoft-graph

使用 composer.json 安装 Microsoft Graph PHP SDKInstall the Microsoft Graph PHP SDK using composer.json

{
    "require": {
        "microsoft/microsoft-graph": "^1.8"
    }
}

安装 Microsoft PowerShellInstall the Microsoft PowerShell SDK

请参阅 Microsoft Graph PowerShell SDKSee Install the Microsoft Graph PowerShell SDK.

安装 Microsoft Graph Ruby SDKInstall the Microsoft Graph Ruby SDK

Microsoft Graph Ruby SDK 已在 packagist.org 中可用,可按以下方法安装:The Microsoft Graph Ruby SDK is available from rubygems.org and can be installed using the following command:

gem install microsoft_graph