在V1中,我可以
$this->graph->createRequest('GET', '/drives/' . $driveId . '/items/' . $itemId . '/content')->download($path);
在V2中如何做到这一点?
我认为这已经很接近了,但我想不出如何在$Response中写入文件.
$tokenRequestContext = new \Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext(
config('graphapi.azure_tenant_id'),
config('graphapi.azure_client_id'),
config('graphapi.azure_client_secret')
);
$graphServiceClient = new \Microsoft\Graph\GraphServiceClient($tokenRequestContext);
$response = $graphServiceClient->drives()
->byDriveId(config('graphapi.attachments_drive_id'))
->items()
->byDriveItemId(<drive_item_id>)
->content()
->get();
编辑:
$Response返回promise :
object(Http\Promise\FulfilledPromise)#5993 (1) {
["result":"Http\Promise\FulfilledPromise":private]=>
object(GuzzleHttp\Psr7\Stream)#6066 (7) {
["stream":"GuzzleHttp\Psr7\Stream":private]=>
resource(965) of type (stream)
["size":"GuzzleHttp\Psr7\Stream":private]=>
NULL
["seekable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["readable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["writable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["uri":"GuzzleHttp\Psr7\Stream":private]=>
string(10) "php://temp"
["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
array(0) {
}
}
}
因此,我将代码更改为:
$promise = $graphServiceClient->drives()
->byDriveId(config('graphapi.attachments_drive_id'))
->items()
->byDriveItemId(<drive_item_id>)
->content()
->get();
$promise->then(
function ($response) {
$fileContent = $response->getBody()->getContents();
file_put_contents('test.txt', $fileContent);
},
function ($exception) {
echo "Error: " . $exception->getMessage();
}
);
但我收到错误:对未定义的方法GuzzleHttp\Psr7\Stream::getBody()的错误调用.