有人可以给我代码来获取spfx Webpart的当前登录用户。我不需要pnp.sp或sp.web,我想使用spHttpClient等。
我在互联网上找不到任何基本代码。链接即可。
问候,
T
示例代码:
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)
})
})