page_type | description | products | languages | ||||
---|---|---|---|---|---|---|---|
sample |
This sample demonstrates how to use the Microsoft Graph JavaScript SDK to access data in Office 365 from SharePoint Framework (SPFX) applications. |
|
|
This sample demonstrates how to use the Microsoft Graph JavaScript SDK to access data in Office 365 from SharePoint Framework (SPFX) applications.
Before you start this tutorial, you should have the following tools installed on your development machine.
You can find more details about requirements for SharePoint Framework development at Set up your SharePoint Framework development environment.
You should also have a Microsoft work or school account, with access to a global administrator account in the same organization. If you don't have a Microsoft account, you can sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 subscription.
Your Microsoft 365 tenant should be setup for SharePoint Framework development, with an app catalog and testing site created before you start this tutorial.
Note
This tutorial was written with the following versions of the above tools. The steps in this guide may work with other versions, but that has not been tested.
- Node.js 16
- Yeoman 4.3.0
- Gulp 2.3.0
- Yeoman SharePoint generator 1.15.2
-
Run the following two commands in your CLI to build and package your web part.
gulp bundle --ship gulp package-solution --ship
-
Open your browser and go to your tenant's SharePoint App Catalog. Select the Apps for SharePoint menu item on the left-hand side.
-
Upload the ./sharepoint/solution/graph-tutorial.sppkg file.
-
In the Do you trust... prompt, confirm that the prompt lists the 4 Microsoft Graph permissions you set in the package-solution.json file. Select Make this solution available to all sites in the organization, then select Deploy.
-
Go to the SharePoint admin center using a tenant administrator.
-
In the left-hand menu, select Advanced, then API access.
-
Select each of the pending requests from the graph-tutorial-client-side-solution package and choose Approve.
-
Go to a SharePoint site where you want to test the web part. Create a new page to test the web part on.
-
Use the web part picker to find the GraphTutorial web part and add it to the page.
-
The access token is printed below the Welcome to SharePoint! message in the web part. You can copy this token and parse it at https://jwt.ms/ to confirm that it contains the permission scopes required by the web part.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.