0
votes

I have a scenario where userA shares a file with userB on OneDrive for Business. They both belong to the same Office365 tenant.

Is there a way to programmatically retrieve shared file content using userB identity (OAuth access token)? I've tried using 2.0 API syntaxt, which works for userA, but I'm getting 401 error when trying to execute this request with userB access token, even though file was shared with userB.

https://{tenantid}-my.sharepoint.com/_api/v2.0/drives/{driveId}/items/{itemId}/

Or maybe there is a way I could use Azure AD Application delegated permission to access this file on behalf of its owner having driveId and itemId?

2

2 Answers

1
votes

As far as I know, this feature is not supported yet.

There is a request for this functionality on UserVoice which you can vote on.

0
votes

As for March 2016, the only way I was able to retrieve shared file content programmatically from OneDrive for Business was by:

  1. Creating SharePoint Provider hosted addin with FullControl permission for the whole Tenant
  2. Registering the app under https://{tenantid}-my.sharepoint.com/_layouts/15/AppRegNew.aspx
  3. Creating app catalog on SharePoint Online and publishing the app to the catalog
  4. Installing app on at least one SharePoint site collection within the Tenant
  5. Using ClientSecret and ClientId executing following code from http://blogs.msdn.com/b/vesku/archive/2015/01/05/customizing-onedrive-for-business-sites-with-app-model.aspx

    Uri url = new Uri("https://{tenantid}-my.sharepoint.com/personal/{user}"); string realm = TokenHelper.GetRealmFromTargetUrl(url); var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal,url.Authority, realm).AccessToken;

  6. token variable contains AccessToken that can be used as Bearer token in OneDrive for Business API requests (e.g. getting files from other users 'OneDrives').

https://{tenantid}-my.sharepoint.com/_api/v2.0/drives/{driveId}/items/{itemId}/