java - 我需要使用什么 pom 才能在 Java 中使用 Azure Graph?

标签 java azure-ad-graph-api

我正在使用 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-graph-auth 可用。另外,我尝试过使用maven安装auth sdk,会出现一些问题。您可以使用Gradle安装auth sdk。

将 microsoft-graph-auth 的存储库和编译依赖项添加到项目的 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();
    }

也可以引用我的回答here .

关于java - 我需要使用什么 pom 才能在 Java 中使用 Azure Graph?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60864125/

相关文章:

java - Android - 在圆圈中移动对象

java - 这两种查找随机数的方法之间的区别?

c# - 通过 GRAPH 更新 Azure AD 中的用户时出现 Json 序列化错误

angularjs - 未使用 acquireTokensilent 获取 token ,但使用 acquireTokenpopup Msal-browser 获取 token

xml - Azure B2C : Where to Create DateTime Extension Attribute to be used in Custom Policy- Portal or Custom Policy or Both?

Spring Boot、Docker 和 EC2 中的 Java 版本

java - 如何在struts2中为自定义拦截器添加exportMethods参数列表

java - 按下一个按钮来保存来自不同 Activity 的地理位置详细信息并将其显示在 MapView 上?

刷新 token 后,Azure AD B2C 访问 token 声明不会更新

azure - Authorization_RequestDenied。权限不足,无法完成操作。图形API