Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Microsoft Graph -- List UsersSee more Microsoft Graph ExamplesRetrieve a list of Microsoft Graph user objects. For more information, see https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Variant vReq Handle hoReq String sUrl Variant vResp Handle hoResp Integer iStatusCode Handle hoJson Boolean iSuccess Variant vSbResponse Handle hoSbResponse Boolean iSuccess String sOdata_id String sDisplayName String sGivenName String sJobTitle String sMail String sMobilePhone String sOfficeLocation String sPreferredLanguage String sSurname String sUserPrincipalName String sId Integer j Integer iCount_j String sOdata_context Integer i Integer iCount_i String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Get an access token with the required scope using client credentials... // See How to Create Microsoft Graph App (in Azure Portal) for Client Credentials Authentication Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get Create (RefClass(cComChilkatHttpRequest)) To hoReq If (Not(IsComObjectCreated(hoReq))) Begin Send CreateComObject of hoReq End Send ComAddParam To hoReq "client_secret" "CLIENT_SECRET" Send ComAddParam To hoReq "client_id" "CLIENT_ID" Send ComAddParam To hoReq "scope" "https://graph.microsoft.com/.default" Send ComAddParam To hoReq "grant_type" "client_credentials" // Use your own tenant ID, for example 4d8fdd66-66d1-43b0-ae5c-e31b4b7de5cd Move "https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token" To sUrl Get pvComObject of hoReq to vReq Get ComPostUrlEncoded Of hoHttp sUrl vReq To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iStatusCode Showln "Response status code = " iStatusCode Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComBodyStr Of hoResp To sTemp1 Get ComLoad Of hoJson sTemp1 To iSuccess Send Destroy of hoResp // ----------------------------------------------------- // Use the access token obtained from above. // Note: We don't need to re-fetch a new access token every time. An access token is valid // for some amount of time, typically an hour (3600 seconds) // Use your previously obtained access token here: Get ComStringOf Of hoJson "access_token" To sTemp1 Set ComAuthToken Of hoHttp To sTemp1 Get ComAuthToken Of hoHttp To sTemp1 Showln "access token: " sTemp1 Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse If (Not(IsComObjectCreated(hoSbResponse))) Begin Send CreateComObject of hoSbResponse End Get pvComObject of hoSbResponse to vSbResponse Get ComQuickGetSb Of hoHttp "https://graph.microsoft.com/v1.0/users" vSbResponse To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoSbResponse to vSbResponse Get ComLoadSb Of hoJson vSbResponse To iSuccess Set ComEmitCompact Of hoJson To False Get ComLastStatus Of hoHttp To iTemp1 Showln "Status code = " iTemp1 Get ComLastStatus Of hoHttp To iTemp1 If (iTemp1 <> 200) Begin Get ComEmit Of hoJson To sTemp1 Showln sTemp1 Showln "Failed." End Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // Sample output // { // "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users", // "value": [ // { // "@odata.id": "https://graph.microsoft.com/v2/6d8ddd66-68d1-43b0-af5c-e31b4b7dd5cd/directoryObjects/fca490d8-5918-4201-8079-c5dcbeafcdc9/Microsoft.DirectoryServices.User", // "businessPhones": [ // ], // "displayName": "Joe Sample", // "givenName": "Joe", // "jobTitle": null, // "mail": null, // "mobilePhone": null, // "officeLocation": null, // "preferredLanguage": null, // "surname": "Sample", // "userPrincipalName": "admin_chilkatsoft.com#EXT#@adminchilkatsoft.onmicrosoft.com", // "id": "fca490d8-5918-4201-8079-c5dcbeafcdc9" // } // ] // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON Get ComStringOf Of hoJson '"@odata.context"' To sOdata_context Move 0 To i Get ComSizeOfArray Of hoJson "value" To iCount_i While (i < iCount_i) Set ComI Of hoJson To i Get ComStringOf Of hoJson 'value[i]."@odata.id"' To sOdata_id Get ComStringOf Of hoJson "value[i].displayName" To sDisplayName Get ComStringOf Of hoJson "value[i].givenName" To sGivenName Get ComStringOf Of hoJson "value[i].jobTitle" To sJobTitle Get ComStringOf Of hoJson "value[i].mail" To sMail Get ComStringOf Of hoJson "value[i].mobilePhone" To sMobilePhone Get ComStringOf Of hoJson "value[i].officeLocation" To sOfficeLocation Get ComStringOf Of hoJson "value[i].preferredLanguage" To sPreferredLanguage Get ComStringOf Of hoJson "value[i].surname" To sSurname Get ComStringOf Of hoJson "value[i].userPrincipalName" To sUserPrincipalName Get ComStringOf Of hoJson "value[i].id" To sId Move 0 To j Get ComSizeOfArray Of hoJson "value[i].businessPhones" To iCount_j While (j < iCount_j) Set ComJ Of hoJson To j Move (j + 1) To j Loop Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.