OneDrive for Business REST API - PUT,POST - 401 Unauthorized

瘦欲@ 提交于 2020-01-03 06:46:05

问题


We've a trial version of Microsoft azure and are playing with the One drive for Business CRUD operations via the REST API from java client as per the link.

After getting the token, I'm able to list any folder, download file and get attributes of a file using GET successfully.

But, the operations such as PUT, POST which are required for create folder, upload file, rename file/folder, etc are not working. I get back "401 UnAuthorized" error.

Error Response json :

{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":"Access denied. You do not have permission to perform this action or access this resource."}}

I set the access token in the similar way how i set for GET in the http request and i'm using jboss rest easy client for accessing the rest API Here is a code for "Creating a folder"

ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();   
ResteasyProviderFactory.pushContext(javax.ws.rs.ext.Providers.class,factory);
ResteasyClientBuilder resteasyClientBuilder = new             
ResteasyClientBuilder().providerFactory(factory);
ResteasyClient client = resteasyClientBuilder.build();
ResteasyWebTarget target = client.target(BASE_URL +"/getByPath('/TestFolder1')");
Invocation.Builder request = target.request();
request.header("Authorization", "Bearer " + this.token);
Response response = request.put(Entity.text(""));

And as per documentation, 401 UnAuthorized error means "Required authentication information is either missing or invalid."

Am i missing any header that's supposed to be in the request/ Any other issue with the request?

来源:https://stackoverflow.com/questions/29515578/onedrive-for-business-rest-api-put-post-401-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!