microsoftgraph / msgraph-sdk-php

Microsoft Graph Library for PHP.
Other
551 stars 141 forks source link

PHP Fatal error: Uncaught Error: Class "Microsoft\Graph\GraphServiceClient" not found #1500

Closed parksmarty closed 2 months ago

parksmarty commented 2 months ago

Hello,

We are trying to convert some code from C# to PHP that is used to get the number of message that are in a group mailbox. We are getting errors trying to get the graph connection going in PHP. The error we are getting is:

PHP Fatal error: Uncaught Error: Class "Microsoft\Graph\GraphServiceClient" not found

Here is the code:

?php require_once '/var/www/html/vendor/autoload.php'; use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext; use Microsoft\Kiota\Abstractions\ApiException; use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAuthenticationProvider; use Microsoft\Graph\GraphServiceClient;

// single-tenant apps must use the tenant ID from the Azure portal $tenantId = "tenant_id";

// Values from app registration $clientId = "client_id"; $clientSecret = "client_secret"; // The client credentials flow requires that you request the // /.default scope, and pre-configure your permissions on the // app registration in Azure. An administrator must grant consent // to those permissions beforehand. $scopes = ['https://graph.microsoft.com/.default'];

$tokenRequestContext = new ClientCredentialContext( $tenantId, $clientId, $clientSecret ); $graphServiceClient = new GraphServiceClient($tokenRequestContext); print_r($graphServiceClient); ?>

Please let me know what we need to do to resolve this error.

Once we get that working, our next step will be to get convert this snippet of code:

       var result = await graphClient.Groups["{guid}"].Conversations.GetAsync();
        if (result?.Value == null)
        {
            Console.WriteLine("No Message?");
        }
        else
        {               
            {
                Console.WriteLine(result.Value.Count);
            }
        }

Any comments that you may have regarding converting that to PHP would be helpful...

Thanks, Marty

SilasKenneth commented 2 months ago

Hi @parksmarty, thank you for trying out the PHP SDK. Sorry about the issue. How did you install the PHP SDK? Seems like there might be an issue with the way you are installing the SDK.

microsoft-github-policy-service[bot] commented 2 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.