尝试上传文件结果为403-不允许回复

时间:2019-05-10 11:30:20

标签: java microsoft-graph onedrive microsoft-graph-files

我正在尝试使用Microsoft REST API将文件上传到OneDrive。 我正在将访问令牌传递给我从Azure AD服务获得的请求:

URL urlTest = new URL("https://graph.microsoft.com/v1.0/me/drive/root:/TestFolder/RaviPdf.pdf:/content");
LOGGER.info("url1  : "+urlTest );

HttpURLConnection httpConn = (HttpURLConnection) urlTest.openConnection();
LOGGER.info("conn1  : "+httpConn );
httpConn.setDoOutput(true);
httpConn.setRequestMethod("PUT");
httpConn.setRequestProperty("Authorization", "Bearer " + accessToken);
httpConn.setRequestProperty("Accept","application/json");
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
httpConn.setRequestProperty("charset","UTF-8");
httpConn.setRequestProperty("Content-Length",Integer.toString(100));

OutputStream os = httpConn.getOutputStream();
os.write(bArray);
os.close();  //don't forget to close the OutputStream
httpConn.connect();
httpResponseCode = httpConn.getResponseCode();
LOGGER.info("httpResponseCode "+httpResponseCode );
//here just printing error stream result 
LOGGER.info("httpConn.getErrorStream())"+httpConn.getErrorStream());

作为回应,我收到此错误:

{
  "error": {
    "code": "notAllowed",
    "message": "You do not have access to create this personal site or you do not have a valid license",
    "innerError": {
      "request-id": "8d09ab84-a922-4713-9643-bbc533af41f9",
      "date": "2019-05-10T11:09:59"
    }
  }
}

0 个答案:

没有答案