当试图使用REST在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);
发布于 2016-03-31 21:02:56
JSON不支持表单post语义--在OneDrive编码的blob中,参数被期望是一个JSON。我还没有使用口香糖,但是像这这样的东西应该能用:
$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,
]
'body' =>
'{
"name": "NewFolder",
"folder": { },
"@name.conflictBehavior": "fail"
}'
];
//Guzzle library sends the code as specified
$res = $this->client->request($method, $url, $options);
https://stackoverflow.com/questions/36247126
复制相似问题