Я пытаюсь использовать 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"
}
}
}