"Empty Payload. JSON content expected" 用图表制作文件夹时 api

"Empty Payload. JSON content expected" When making a folder with the graph api

我使用以下代码使用 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();

此returns以下错误:

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();