首页 文章

office 365 onedrive - 获取文件未经身份验证的错误

提问于
浏览
0

我正在为客户开发一个目标C的ios应用程序 . 它涉及onedrive(sharepoint)的office 365 api使用 . 我正在使用来自github的OfficeDev / Office-365-SDK-for-iOS库 . azure已正确设置为办公室365.应用程序设置为azure与所有权限 . 但是我不是管理员 .

通过该应用程序,我可以登录onedrive并能够获取令牌 . 使用“https://api.office.com/discovery/me/services ", I am able to fetch the services. However when I am trying get files with " https://xxx-my.sharepoint.com/_api/v1.0/me/files/root1/”,我收到以下错误:

错误:

getFiles错误:错误域=请求代码中的错误= 403“操作无法完成 . (请求错误403中的错误 . )”UserInfo = 0x170260980 {error = {code =“ - 2147024891,System.UnauthorizedAccessException”; message =“访问被拒绝 . 您无权执行此操作或访问此资源 . ”; }}

任何人都可以面对这样的问题..

1 回答

  • 0

    您已拥有的访问令牌仅用于服务发现 . 您需要获取特定服务的访问令牌 . 有关详细信息,请参阅https://msdn.microsoft.com/en-us/office/office365/howto/discover-service-endpoints .

    所以,基本上你需要再执行一次请求:

    POST https://login.microsoftonline.com/common/oauth2/token 
    {
      'grant_type': 'refresh_token',
      'client_id': <your client_id>,
      'client_secret': <your client_secret>,
      'refresh_token': <refresh token that you already have>,
      'resource': <resource_id of resource you want to access>
    }
    

    它将返回访问令牌,您可以使用该令牌访问特定的服务API .

相关问题