我使用下面的代码来使用microsoft graph api创建一个新的文件夹。
$tokenCache = new TokenCache();
$accessToken = $tokenCache->getAccessToken();
$graph = new Graph();
$graph->setAccessToken($accessToken);
$queryParams = array(
'name' => 'nameOfnewFolder',
'folder' => new \stdClass(),
'microsoft.graph.conflictBehavior' => 'rename'
);
$url = '/me/drive/root/children?' . http_build_query($queryParams);
return $this->graph->createRequest('POST', $url)
->setReturnType(Model\DriveItem::class)
->execute();
这将返回以下错误。
Empty Payload. JSON content expected.
我到底做错了什么?
找到了答案。
你可以使用json添加。
->attachBody($queryParams)
如这里所示。
return $this->graph->createRequest('POST', $url)->addHeaders(array("Content-Type" => "application/json"))
->attachBody($queryParams)
->setReturnType(Model\DriveItem::class)
->execute();