2016-03-27 37 views
0

REST APIを使用してOneDriveでフォルダを作成しようとすると問題が発生します。次のドキュメントページhttps://dev.onedrive.com/items/create.htmを使用しています。私は正常に認証され、トークンは他のエンドポイントで正常に動作しています。フォルダ作成時のOneDrive REST APIエラー400

私は今1日以上かけて、これに対して可能なすべてのURI /メソッドの組み合わせを試してみましたが、成功しませんでした。他のすべてのエンドポイント(ディレクトリリストなど)はOKです。ちょうど私が狂ってしまいます。

私のアプローチで誰かが私にエラーを指摘する可能性がある場合は、どんな助けにも感謝します。

次のコードは、次のようなメッセージでエラー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); 

答えて

1

OneDrive APIは、フォームポストのセマンティクスをサポートしていません - パラメータは、JSONエンコードされたブロブとして体内に期待されています。私はGuzzleを使用していませんが、thisのようなものは動作します:

$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); 
+0

ありがとう!それはあなたが提案したとおりに動作します:)私は$ url = '/drive/items/'.$data->id.//children/'でPOST requestonを使用しました;データIDはGETの/ドライブ/ルート:/ '.$ parentFolderName。'/'。 –

関連する問題