我一直在尝试根据此OneDrive Release Notes实施OneDrive Business API。我们已经实现了OneDrive最终用户API而没有任何问题。
首先要做的事情是处理OAuth2身份验证以获取正确的令牌,首先发现{tenant} -my.sharepoint.com特定的租户OneDrive业务URI,然后获取该租户的令牌。可以找到为此目的的文件here。
按照该教程,我们可以执行以下操作:
可以理解,我们在第2步上遇到了问题, 发现OneDrive for Business资源URI 和 向OneDrive API发出请求
此过程的这一部分存在的问题是,虽然我们正在使用第一个访问令牌 api.office.com/discovery/v2.0/me/services strong>使用资源 api.office.com/discovery / 进行兑换后获得,我们没有进入OneDrive for Business的服务租户特定共享点URI列表。列表中的任何条目我们都会根据capability = "MyFiles" AND serviceApiVersion = "v2.0"
提供文档。实际上,列表中的任何条目在serviceEndpointUri中都具有{tenant} -my.sharepoint.com结构。这是我回来的JSON响应。我删除了一些敏感数据:
{
"@odata.context" : "https://api.office.com/discovery/v2.0/me/$metadata#allServices",
"value" : [ {
"capability" : "Directory",
"providerName" : "Microsoft",
"serviceAccountType" : 2,
"serviceApiVersion" : "",
"serviceEndpointUri" : "http://azure.microsoft.com/",
"serviceName" : "Microsoft Azure",
"serviceResourceId" : null
}, {
"capability" : "MyFiles",
"providerName" : "Microsoft",
"serviceAccountType" : 2,
"serviceApiVersion" : "",
"serviceEndpointUri" : "http://www.microsoft.com/en-us/office365/online-software.aspx",
"serviceName" : "Office 365 SharePoint",
"serviceResourceId" : null
}, {
"capability" : "RootSite",
"providerName" : "Microsoft",
"serviceAccountType" : 2,
"serviceApiVersion" : "",
"serviceEndpointUri" : "http://www.microsoft.com/en-us/office365/online-software.aspx",
"serviceId" : "O365_SHAREPOINT",
"serviceName" : "Office 365 SharePoint",
"serviceResourceId" : null
}, {
"capability" : "MyFiles",
"providerName" : "Microsoft",
"serviceAccountType" : 1,
"serviceApiVersion" : "",
"serviceEndpointUri" : "https://g.live.com/8seskydrive/HomePageUrl",
"serviceName" : "OneDrive",
"serviceResourceId" : null
} ]
}
问题是如果我登录到我的portal.office.com并检查我的sharepoint网址,它配置得很好,我可以看到{tenant} -my.sharepoint.com URI。
我无法发现正确的租户sharepoint URI ,如果我使用我的租户sharepoint URI对下一个访问令牌请求进行硬编码 strong>,我正在获取一个访问令牌,但是当我想打电话给https://{tenant}-my.sharepoint.com/drive/root
或任何其他端点时,我会在每次通话中获得401 Unauthorize响应,即使刚刚获得了令牌。这是握手示例。我隐藏了敏感数据:
curl -v 'https://{tenant}-my.sharepoint.com/drives' -H 'Authorization: Bearer TOKEN_ACQUIRED'
Connected to {tenant}-my.sharepoint.com port 443
GET /drives HTTP/1.1
Host: {tenant}-my.sharepoint.com
Authorization: Bearer TOKEN_ACQUIRED
HTTP/1.1 401 Unauthorized
你能用这个建议吗?我的租户中是否缺少某些配置?我的Azure AD App中是否缺少某些配置?
顺便说一句,我在每次兑换时获得的权限范围都是AllSites.FullControl AllSites.Manage MyFiles.Write Sites.Search.All TermStore.ReadWrite.All User.Read.All
。我想我已经正确设置了权限。
最佳,
列出项目
答案 0 :(得分:0)
可能会有点晚,但这个blog article解决了如何使用OneDrive API和OneDrive for Business API完全相同的问题。 这是一个快速的Java代码片段:
CloudRail.setAppKey("[CloudRail License Key]");
// CloudStorage cs = new OneDrive(redirectReceiver, "[clientIdentifier]", "[clientSecret]", "[redirectUri]", "[state]");
CloudStorage cs = new OneDriveBusiness(redirectReceiver, "[clientID]", "[clientSecret]", "[redirectUri]", "[state]");
new Thread() {
@Override
public void run() {
cs.createFolder("/TestFolder");
InputStream stream = null;
try {
stream = getClass().getResourceAsStream("Data.csv");
long size = new File(getClass().getResource("Data.csv").toURI()).length();
cs.upload("/TestFolder/Data.csv", stream, size, false);
} catch (Exception e) {
// TODO: handle error
} finally {
// TODO: close stream
}
}
}.start();