无法使用Rest API在一个驱动器中创建文件夹

时间:2019-05-16 07:11:15

标签: rest onedrive office365api

使用创建文件夹rest api时获取403禁止状态代码 给出的当前权限是:

委派(工作帐户)的Files.ReadWrite,Files.ReadWrite.All,Sites.ReadWrite.All

Application Files.ReadWrite.All,Sites.ReadWrite.All

我正在使用OneDrive Rest APi文档中提到的以下rest api创建新文件夹。我能够创建该文件夹并上传文档。

https://api.onedrive.com/v1.0/drive/items/” + rootFolderId +“ / children?accessToken =” + accessToken;

String json =“ {\” name \“:\”“ + folderName +” \“,\”文件夹\“:{}}”;

    String folderId = null;
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    CloseableHttpResponse httpResponse = null;
    HttpPost request = null;
    try {
        request = new HttpPost(requestURL);
        StringEntity params = new StringEntity(json);
        request.addHeader("content-type", OneDriveAuthConstants.JSON_CONTENT);
        request.addHeader("Authorization", getAuthorizationHeaderForAccessToken(accessToken));
        request.setEntity(params);
        httpResponse = httpClient.execute(request);
        if (httpResponse.getStatusLine().getStatusCode() == OneDriveAuthConstants.HTTP_RESOURCE_CREATED
                || httpResponse.getStatusLine().getStatusCode() == OneDriveAuthConstants.HTTP_OK) {

            Map<String, String> map = new HashMap<String, String>();
            map = OneDriveUtils.handleResponse(httpResponse);
            folderId = map.get("id");

        }

    }

0 个答案:

没有答案