【发布时间】:2021-05-27 17:36:52
【问题描述】:
-
包 com.example.GraphMS_API.service;
导入 java.util.Arrays;
导入 com.azure.identity.UsernamePasswordCredential;进口 com.azure.identity.UsernamePasswordCredentialBuilder;进口 com.microsoft.graph.authentication.TokenCredentialAuthProvider; 导入 com.microsoft.graph.models.User;进口 com.microsoft.graph.requests.GraphServiceClient;
公共类应用程序{
public static void main(final String args[]) { final UsernamePasswordCredential usernamePasswordCredential = new用户名密码凭据生成器() .clientId("dfdfjhf").username("abc@xyz.com") .password("1234").build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider =新的 TokenCredentialAuthProvider( Arrays.asList("Mail.ReadWrite.Shared"), usernamePasswordCredential);最终的 GraphServiceClient graphClient = GraphServiceClient.builder() .authenticationProvider(tokenCredentialAuthProvider).buildClient();
final User me = graphClient.me().buildRequest().get(); System.out.println(me.companyName); } }
【问题讨论】:
-
请在问题中添加代码,以便人们可以帮助您。