【发布时间】:2016-04-01 05:02:56
【问题描述】:
尝试使用 REST API 在我的 OneDrive 中创建文件夹时遇到问题。我正在使用以下文档页面https://dev.onedrive.com/items/create.htm。我已成功通过身份验证,并且令牌在其他端点上工作正常。
我现在花了一天多的时间尝试所有可能的 URI/方法组合,但没有成功。所有其他端点(目录列表等)都可以,只是这个让我发疯。
如果有人能指出我方法中的错误,我们将不胜感激。
以下代码返回错误 400 并显示以下消息:
{"error":{"code":"invalidRequest","message":"The request is malformed or incorrect."}}
我正在使用GuzzlePhp 库来处理请求。我的代码(简化):
$parentId = '01WZZ7ZY2LNHB75JADQJD3GGUQFSCRRZTQ'; //id to root
$method = "POST";
//none of these does the trick (to be clear, I use only one at the time)
$url = '/_api/v2.0/drive/items/'.$parentId.'/NewFolder'; //put
$url = '/_api/v2.0/drive/items/'.$parentId.'/children'; //put
$url = '/_api/v2.0/drive/items/'.$parentId.'/children'; //post
$url = '/_api/v2.0/drive/root:/NewFolder'; //post
$options = [
'headers' => [
'Authorization' => $token,
'Content-Type' => 'application/json',
'Content-Length'=> 0,
]
'form_params' => [
"name" => "NewFolder",
"folder" => (object)[],
"@name.conflictBehavior" => "fail"
]
];
//Guzzle library sends the code as specified
$res = $this->client->request($method, $url, $options);
【问题讨论】: