How to call the Microsoft GRAPH API on a SharePoint Online page

I need to call the GRAPH API on a SharePoint Online page. Can anyone share an example JavaScript? The examples available on the GRAPH site are designed to invoke the GRAPH API from outside SharePoint Online.

I know that each request requires a token, and you must log in to get this token. However, if I call the GRAPH API from SharePoint Online, it means that I have already authenticated, so again it makes no sense to log in. The token must be available somewhere, and I don’t know how to get it (it is not available in the SharePoint URL).

+4
source share
6 answers

Microsoft Azure AD, OAuth .

, - SharePoint Microsoft Graph.

SharePoint:

- Azure ACS, GUID - 00000001-0000-0000-c000-000000000000. GUID GUID GUID .

Microsoft:

- -. https://sts.windows.net/049bef5f-8841-4000-984b-c3f36bdb2d8c/.

, Microsoft Graph - SharePoint. -, Client Credentials, Microsoft Graph.

, , Microsoft Graph , .

+2

- SharePoint , ACS . Microsoft Graph AAD STS. Microsoft Graph SharePoint, , Microsoft Graph. Microsoft Graph CORS, XHR SharePoint. - SSO. : ACS API CSOM STS Microsoft Graph.

+1

2018 Microsoft MSGraphClient Microsoft Graph. GraphHttpClient .

: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph

Microsoft, -:

export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
 public render(): void {
   // ...

   const client: MSGraphClient = this.context.serviceScope.consume(MSGraphClient.serviceKey);
   // get information about the current user from the Microsoft Graph
   client
     .api('/me')
     .get((error, response: any, rawResponse?: any) => {
       // handle the response
   });
 }

 // ...
}
+1

. SharePoint, . API , Office Graph.

https://msdn.microsoft.com/en-us/office/office365/howto/query-office-graph-using-gql-with-search-rest-api

, ( - , ):

/_api/search/query?QueryText='*'
&Properties='GraphQuery:ACTOR(ME\,action\:1021)'
&RowLimit=5
&SelectProperties='URL,Title,ModifiedOWSDate,ModifiedBy,ContentType'
&sortlist='created:1'

, ( , Delve).

, !

UPDATE:

. https://msdn.microsoft.com/en-us/office/office365/howto/query-office-graph-using-gql-with-search-rest-api

0

, GraphHttpClient, - Microsoft Graph - SharePoint Framework.

Mikael Svenson , -.

0

You will need to use adaljs to get the azure ad marker. His explanation here is pretty good https://dev.office.com/sharepoint/docs/spfx/web-parts/guidance/call-microsoft-graph-from-your-web-part

-2
source

Source: https://habr.com/ru/post/1654248/


All Articles