0

I am trying to retrieve information on Users using the Microsoft Graph Library for PHP.

I can see that in GraphResponse.php, my $result is filled with correct data but the code does not find the Model\User-class.

$user = $graph->createRequest("GET", "/users")
              ->setReturnType(Model\User::class)
              ->execute();

Since I am not familiar with this autoload-thing, I am stuck. Any help appreciated.

Is there any better documentation for this subject???

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Odido
  • 13
  • 7

1 Answers1

0

It appears you're experiencing some troubles with installing msgraph-sdk-php package and that's the reason why Model\User type could not be resolved in your case. If you are following the official Getting Started documentation, there is a typo regarding package name in Installation section:

{
    "require": {
        "Microsoft/Graph": "^1.0"
    }
}

and while installing you should get the error like this

The requested package microsoft/graph could not be found in any version, there may be a typo in the package name.

Instead of Microsoft/Graph the valid name should be microsoft/microsoft-graph, for example:

{
    "require": {
        "microsoft/microsoft-graph": "^1.6"
    }
}

Once the package is installed successfully, the minimal example for retrieving users could look like this:

require_once './vendor/autoload.php';

use \Microsoft\Graph\Graph;

$accessToken = "--YOUR-ACCESS-TOKEN-GOES-HERE--";

$graph = new Graph();
$graph->setAccessToken($accessToken);

$user = $graph->createRequest("GET", "/users")
    ->setReturnType(\Microsoft\Graph\Model\User::class)
    ->execute();
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193