microsoft graph api - How to find owners of applications - Stack Overflow

admin2025-04-17  2

In the MS Graph Java SDK 6.1, I am trying to determine the owners of a given application. I have the application ID.

I am trying to use this sample code

// Fetch the owners of the application
List<DirectoryObject> owners = graphClient
        .applications(applicationId)
        .owners()
        .buildRequest()
        .get()
        .getCurrentPage();

However, applications no longer takes a parameter applicationId, and applicationsByAppId(appId) does not have a method owners().

All of my searches have returned the above code, so clearly the SDK has changed very recently. None of the samples in the SDK docs deal with this either.

I've also tried this code below, where the SDK does have the getOwners method, but it always returns null despite the application clearly having multiple owners specified.

ApplicationCollectionResponse resp = graphClient.applications().get(requestConfiguration -> {
    requestConfiguration.queryParameters.select = new String[] { "id", "displayName", "appId", "passwordCredentials" };
});

results = new ArrayList<>();
List<Application> apps = resp.getValue();

while (apps != null && apps.size() > 0) {
    for (Application app : apps) {
        // Fetch the owners of the application
        if (app.getOwners() != null) {
            for (DirectoryObject dirobj : app.getOwners()) {
                    logger.debug("App {} has owner {}", app.getDisplayName(), dirobj.getId());
            }
        }

In the MS Graph Java SDK 6.1, I am trying to determine the owners of a given application. I have the application ID.

I am trying to use this sample code

// Fetch the owners of the application
List<DirectoryObject> owners = graphClient
        .applications(applicationId)
        .owners()
        .buildRequest()
        .get()
        .getCurrentPage();

However, applications no longer takes a parameter applicationId, and applicationsByAppId(appId) does not have a method owners().

All of my searches have returned the above code, so clearly the SDK has changed very recently. None of the samples in the SDK docs deal with this either.

I've also tried this code below, where the SDK does have the getOwners method, but it always returns null despite the application clearly having multiple owners specified.

ApplicationCollectionResponse resp = graphClient.applications().get(requestConfiguration -> {
    requestConfiguration.queryParameters.select = new String[] { "id", "displayName", "appId", "passwordCredentials" };
});

results = new ArrayList<>();
List<Application> apps = resp.getValue();

while (apps != null && apps.size() > 0) {
    for (Application app : apps) {
        // Fetch the owners of the application
        if (app.getOwners() != null) {
            for (DirectoryObject dirobj : app.getOwners()) {
                    logger.debug("App {} has owner {}", app.getDisplayName(), dirobj.getId());
            }
        }
Share Improve this question edited Feb 2 at 13:24 user2250152 21.3k4 gold badges43 silver badges66 bronze badges asked Jan 31 at 20:22 Richard SandRichard Sand 6747 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I'm afraid it requires two steps:

  1. Get application by appId
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);

Application app = graphClient.applicationsWithAppId("{appId}").get();
  1. Use application object id to get owners
DirectoryObjectCollectionResponse owners = graphClient.applications().byApplicationId(app.getId()).owners().get();
转载请注明原文地址:http://anycun.com/QandA/1744848008a88459.html