1

I'm working with Spring and I want to set my pom so I can perform calls to the Azure Graph API in Java. The relevant parts of my pom are:

<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>

When I perform a call to know the information about a user with the method I'm getting an error in com.microsoft.graph.requests.extensions.UserCollectionRequest.get. I'm getting the following stacktrace:

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]

Any idea how can I fix this?

Carabes
  • 532
  • 2
  • 4
  • 16

1 Answers1

0

It seems that only 0.1.0-SNAPSHOT version of microsoft-graph-auth is available. Also, I have tried to use maven to install the auth sdk, there will be some issues. You can use Gradle to install the auth sdk.

Add the repository and a compile dependency for microsoft-graph-auth to your project's 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')
}

Here is a working sample for your reference:

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();
    }

You can also refer to my answer here.

Tony Ju
  • 14,891
  • 3
  • 17
  • 31