我正在尝试访问组织的 SharePoint 团队网站。我使用 Microsoft Graph API,因为它是 Office 365 最完整的 API。我了解如何获取访问令牌以及如何使用它来发出请求。我知道它有效,因为我可以获得组列表,但是当涉及到获取所有团队网站时,我收到一条错误消息:
Code : invalidRequest
Message : Cannot enumerate sites
这是我的代码。我正在控制台应用程序中测试它。
class Program {
static void Main(string[] args) {
Program p = new Program();
var items = p.GetItems();
items.Wait();
foreach (var item in items.Result) {
Console.WriteLine(item.DisplayName);
}
Console.ReadLine();
}
public async Task<IGraphServiceSitesCollectionPage> GetItems() {
PublicClientApplication myApp =
new PublicClientApplication("CLIENT-ID-FROM-DEVELOPPER-CONSOLE");
//Gets an access token
AuthenticationResult authenticationResult =
await myApp.AcquireTokenAsync(
new string[] {
"user.read.all",
"sites.read.all",
"files.read.all",
"group.read.all",
"Directory.Read.All"
}).ConfigureAwait(false);
//Creates the client with the access token
GraphServiceClient graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async(requestMessage) => {
// Append the access token to the request.
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("bearer",
authenticationResult.AccessToken);
}));
//Requests the site objects
var sites = await graphClient.Sites.Request().GetAsync();
return sites;
}
}
我用谷歌搜索了很多,只找到了对我不起作用的解决方案。
该错误消息为您提供了有关此操作不起作用的原因的准确描述。
致电给graphClient.Sites.Request().GetAsync()
被翻译成HTTP调用https://graph.microsoft.com/sites
这不是有效的 API 端点。
您需要提供一些额外的上下文,例如site
您正在寻找。例如,要获取根站点,您可以调用:
graphClient.Sites["root"].Request().GetAsync();
如果您正在寻找团队网站,您可以使用该网站的路径:
await graphClient.Sites["root"].SiteWithPath("/teams/myawesometeam").Request().GetAsync();
有关其他 SharePoint 端点,请参阅图表 SharePoint 文档 https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/sharepoint.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)