문제

I am currently using the following endpoints to access user specific sites (followed, frequent and suggested)

/_vti_bin/homeapi.ashx/sites/followed
/_vti_bin/homeapi.ashx/sites/recent
/_vti_bin/homeapi.ashx/sites/suggested

Both the /followed and /suggested work perfectly well, however the /recent is only giving me this output :

{
    "HttpStatus": "InternalServerError",
    "ErrorMessage": "Office graph is disabled.",
    "ErrorCode": 500011
}

According to brannmar (and the accepted answer) and after testing, the /recent endpoint does work with the added header SPHome-ClientType: SharePointIOS but from what he is saying, I won't be able to use this in a prodution environment.

I don't feel strongly about this endpoint particularly but I have not found any endpoint in Graph or the actual SharePoint Rest API that does something remotely similar.

I found these endpoints in various posts :

REST API to get Frequent Sharepoint Sites programmatically?

How to programmatically get Frequent Sharepoint Sites using REST API?

Office 365: The New SharePoint Homepage

The second post is the most interesting as you can see the issue was already here in dec-17 / jan-18. The OP suggests he posted a feedback on https://office365.uservoice.com but I can't seem to find it.

I have also tried using the endpoint used by the SharePoint Portal (https://<tenant>/_layouts/15/sharepoint.aspx) but I get an Unauthorized Access Exception because i don't know how to authenticate for this call.

Uri: https://northeurope1-sphomep.svc.ms/api/v1/sites/recent

The call is made only once (then it is cached probably in a hidden list on the user MySite) and uses a JWT Bearer Token (mine doesn't seem to work, but I guess it's normal since it's a token for my tenant)

I'm open to any suggestion !

도움이 되었습니까?

해결책

I dont know if you have gotten a answer to this question some other way but here is a possible solution to your Office graph is disabled problem.

By simply adding an extra header to your request it should solve your problem.

SPHome-ClientType: SharePointIOS

I dont know why this works but it does. And also this it not a documented API from Microsoft so I would not use it in production. I have noticed multiple 500 errors when using it.

다른 팁

Using the GRAPH API

The recently Visited Sites webpart from the sharepoint sp-starter-kit, already shows the latest visited sites by the current user with the help of graph api.

This webpart gets the latest web pages the user has visited, on the endpoint:

https://graph.microsoft.com/v1.0/me/insights/used?$filter=ResourceVisualization/containerType eq 'Site' and ResourceVisualization/Type eq 'Web'

Then, builds an array of unique site url based on the results returned by the query.

You can follow the same approach in your scenario, HOWEVER, these results are always based on visited page items or files, then, if a user only visits the site homepage, such result wont be reflected in the query answer.

CONCLUSION: use Sharepoint REST API

If you are looking for an accurate result array of latest visited sites, best thing is to query the below enpoint ( replace top with number of desired results )

/_vti_bin/homeapi.ashx/sites/recent??mostRecentFirst=true&start=0&count=${top}&acronyms=true

And dont forget to add the additional header SPHome-ClientType. Here is a javascript example:

return await (await this.httpCli.get(
        `/_vti_bin/homeapi.ashx/sites/recent??mostRecentFirst=true&start=0&count=${top}&acronyms=true`,
        SPHttpClient.configurations.v1,
        { headers: { "SPHome-ClientType": "SharePointIOS" } })
      ).json();

PS1: feel free to test the microsoft graph api here

PS2: This sharepoint rest api will be exposed and documented some day in graph api, as described on this github thread.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top