"Empty Payload. 期待JSON内容",当使用图形api制作文件夹时

问题描述 投票:0回答:1

我使用下面的代码来使用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.

我到底做错了什么?

php microsoft-graph microsoft-graph-files
1个回答
0
投票

找到了答案。

你可以使用json添加。

->attachBody($queryParams)

如这里所示。

 return $this->graph->createRequest('POST', $url)->addHeaders(array("Content-Type" => "application/json"))
                ->attachBody($queryParams)
                ->setReturnType(Model\DriveItem::class)
                ->execute();
© www.soinside.com 2019 - 2024. All rights reserved.