在Java中使用Azure Graph需要使用什么pom



我正在使用Spring,我想设置我的pom,这样我就可以在Java中执行对Azure Graph API的调用。我的pom的相关部分是:

<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>1.7.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-auth</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>1.0.0</version>
</dependency>

当我用方法执行调用以了解用户信息时,我在com.microsoft.graph.requests.extensions.UserCollectionRequest.get中得到了一个错误。我得到了以下堆叠竞赛:

java.lang.NoSuchMethodError: okhttp3.Request$Builder.tag(Ljava/lang/Class;Ljava/lang/Object;)Lokhttp3/Request$Builder;
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:268) ~[microsoft-graph-1.7.1.jar!/:na]
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:204) ~[microsoft-graph-1.7.1.jar!/:na]
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:184) ~[microsoft-graph-1.7.1.jar!/:na]
at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:89) ~[microsoft-graph-1.7.1.jar!/:na]
at com.microsoft.graph.requests.extensions.UserCollectionRequest.get(UserCollectionRequest.java:52) ~[microsoft-graph-1.7.1.jar!/:na]
at util.MicrosoftGraphService.getUserByEmail(MicrosoftGraphService.java:70) ~[classes!/:na]

知道我该怎么解决吗?

似乎只有0.1.0-SNAPSHOT版本的microsoft图形验证可用。此外,我曾尝试使用maven安装auth-sdk,但会出现一些问题。您可以使用Gradle来安装auth-sdk。

将存储库和microsoft图形验证的编译依赖项添加到项目的build.gradle 中

repository {
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependency {
// Include the sdk as a dependency
compile('com.microsoft.graph:microsoft-graph-auth:0.1.0-SNAPSHOT')
}

这里有一个工作样本供您参考:

public static void main(String [] rags){
UsernamePasswordProvider authProvider = new UsernamePasswordProvider("{client_id}", Arrays.asList("https://graph.microsoft.com/User.Read.All") , "{username}", "{password}", NationalCloud.Global, "{tenant}", "{cient_secret}");
IGraphServiceClient graphClient = GraphServiceClient
.builder()
.authenticationProvider(authProvider)
.buildClient();
IUserCollectionPage userCollectionPage = graphClient.users().buildRequest().get();
List<User> userList=userCollectionPage.getCurrentPage();
}

你也可以在这里参考我的答案。

最新更新