phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

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

Open ghost opened this issue 4 years ago • 2 comments

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
        }
    ]
]

ghost avatar Dec 09 '20 05:12 ghost

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

stmn avatar Dec 07 '23 15:12 stmn