0

我使用以下代码使用 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.

我在这里做错了什么?

4

1 回答 1

0

找到遮阳篷:

可以使用以下方法添加 json:

->attachBody($queryParams)

如此处所示:

 return $this->graph->createRequest('POST', $url)->addHeaders(array("Content-Type" => "application/json"))
                ->attachBody($queryParams)
                ->setReturnType(Model\DriveItem::class)
                ->execute();
于 2020-05-14T10:33:08.277 回答