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
(PowerBuilder) Get Google Account Info from OAuth2 Access TokenSee more Google APIs ExamplesIn the Google OAuth2 authorization flow, an application can know the email address of the Google account used to authorize access by requesting and processing user information from the Google UserInfo endpoint after obtaining an access token.
integer li_rc oleobject loo_Http integer li_Success oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_V_sub string ls_Name string ls_Given_name string ls_Family_name string ls_Profile string ls_Picture string ls_Email integer li_Email_verified string ls_Locale // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // Implements the following CURL command: // curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://www.googleapis.com/oauth2/v3/userinfo // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Adds the "Authorization: Bearer YOUR_ACCESS_TOKEN" header. loo_Http.AuthToken = "YOUR_ACCESS_TOKEN" loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Http.QuickGetSb("https://www.googleapis.com/oauth2/v3/userinfo",loo_SbResponseBody) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_SbResponseBody return end if loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Http.LastStatus Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Http.LastHeader Write-Debug "Failed." destroy loo_Http destroy loo_SbResponseBody destroy loo_JResp return end if // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "sub": "112233445678901234567", // "name": "John Doe", // "given_name": "John", // "family_name": "Doe", // "profile": "https://plus.google.com/112233445678901234567", // "picture": "https://lh3.googleusercontent.com/a-/AOh14GiU-EXAMPLE", // "email": "johndoe@example.com", // "email_verified": true, // "locale": "en" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON ls_V_sub = loo_JResp.StringOf("sub") ls_Name = loo_JResp.StringOf("name") ls_Given_name = loo_JResp.StringOf("given_name") ls_Family_name = loo_JResp.StringOf("family_name") ls_Profile = loo_JResp.StringOf("profile") ls_Picture = loo_JResp.StringOf("picture") ls_Email = loo_JResp.StringOf("email") li_Email_verified = loo_JResp.BoolOf("email_verified") ls_Locale = loo_JResp.StringOf("locale") destroy loo_Http destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.