簡體   English   中英

從 Sharepoint 獲取 Graph API 有效訪問令牌 在線登錄

[英]Get Graph API valid access token from Sharepoint Online login

實際上,我必須在 Sharepoint Online 上發布自定義整頁(不使用現代頁面,只需購買一個簡單的 aspx)並通過 javascript 調用 Graph API。

為此,我需要一個訪問令牌,但我不知道如何從 Sharepoint 登錄 session 獲取它。 我注意到登錄后session中有很多變量,帶有各種令牌,但沒有一個適合調用圖形api

我怎樣才能做到這一點?

您可以使用名為MSGraphClient的 class 連接到 Microsoft Graph。

這里有一個例子。

export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
  public render(): void {
    // ...

    this.context.msGraphClientFactory
      .getClient()
      .then((client: MSGraphClient): void => {
        // get information about the current user from the Microsoft Graph
        client
          .api('/me')
          .get((error, response: any, rawResponse?: any) => {
            // handle the response
        });
      });
  }

  // ...
}

請參閱Use the MSGraphClient to connect to Microsoft Graph and Consume the Microsoft Graph in the SharePoint Framework 中的參考資料

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM