Alex T.
Alex T.

Reputation: 33

Microsoft Graph SDK PHP: CreateRequest not working

I am trying to use the Microsoft Graph SDK PHP.

I have simple directory with index.php and vendor (created exactly as requested in the related github project: https://github.com/microsoftgraph/msgraph-sdk-php).

My index.php file looks like:

require_once("./vendor/autoload.php");

use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;

$accessToken = 'xxx'; // Here I would insert the access token

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

// Code that is not working:
$user = $graph->createRequest("GET", "/me")
   ->setReturnType(Model\User::class)
   ->execute();

echo "Hello, I am $user->getGivenName() ";

The issue; createRequest is not working (the php file stop to be executed)... And I have no idea why, as I have just copied the sample code of the Github project.

What do I do wrong?

Thank you for your help :)

Upvotes: 1

Views: 939

Answers (1)

Alex T.
Alex T.

Reputation: 33

Answer: Apparently, any error in the access token will always make it crash. The code is therefore working.

Upvotes: 1

Related Questions