vgrem / phpSPO

Microsoft 365 Library for PHP.
MIT License
350 stars 112 forks source link

$message->HasAttachments is true but ->Attachments and ->getAttachments() are both null #214

Open ghost opened 3 years ago

ghost commented 3 years ago

Using v2.4.3

I'm hoping this is user error on my part. If anyone could please advise it would be much appreciated.

Code

function acquireToken(AuthenticationContext $authCtx,$clientId,$userName,$password)
{
    $resource = "https://outlook.office365.com";
    try {
        $authCtx->acquireTokenForPassword($resource, $clientId,
            new UserCredentials($userName, $password));
    } catch (Exception $e) {
        print("Failed to acquire token");
    }
}

$client = null;

try {
    $client = new OutlookClient($settings['TenantName'],function (AuthenticationContext $authCtx) use($settings) {
       acquireToken($authCtx,$settings['ClientId'],$settings['UserName'], $settings['Password']);
    });

    $messages = $client->getMe()->getMessages();
    $client->load($messages);
    $client->executeQuery();

    $test = [];

    foreach ($messages->getData() as $message) {
        $test[] = [
            $message->HasAttachments,
            $message->Attachments,
            $message->getAttachments()
        ];
    }

    file_put_contents('attachments.json', json_encode($test, JSON_PRETTY_PRINT));
}
catch (Exception $e) {
    echo 'Authentication failed: ',  $e->getMessage(), "\n";
}

Results in:

[
    [
        false,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        false,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        false,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        false,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        false,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        true,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        true,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        true,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        true,
        null,
        {
            "NextRequestUrl": null
        }
    ],
    [
        true,
        null,
        {
            "NextRequestUrl": null
        }
    ]
]
stmn commented 7 months ago

It is still not working right? Library is not usable to download attachments?

// edited Ok, nevermind, I migrated to official sdk https://github.com/microsoftgraph/msgraph-sdk-php