如何使用sphttp(不是sp.web或pnp)spfx获取用户当前标题

问题描述 投票:0回答:1

有人可以给我代码来获取spfx Webpart的当前登录用户。我不需要pnp.sp或sp.web,我想使用spHttpClient等。

我在互联网上找不到任何基本代码。链接即可。

问候,

T

sharepoint-online spfx sharepoint-rest-api
1个回答
0
投票

示例代码:

import { SPHttpClient, SPHttpClientResponse,ISPHttpClientOptions} from '@microsoft/sp-http';    
this.context.spHttpClient.get(`${this.context.pageContext.web.absoluteUrl}/_api/SP.UserProfiles.PeopleManager/GetMyProperties`,
      SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) =>{
        response.json().then((responseJSON: any) => { 
          console.log(responseJSON.DisplayName)
         })
      })
© www.soinside.com 2019 - 2024. All rights reserved.