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
(Unicode C) Moody's REST API - Get OAuth2 TokenSee more Moody's ExamplesDemonstrates how to get an OAuth2 access token for the Moody's REST API.
#include <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkFileAccessW.h> void ChilkatSample(void) { HCkHttpW http; HCkHttpRequestW req; HCkHttpResponseW resp; const wchar_t *responseBody; HCkFileAccessW fac; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); req = CkHttpRequestW_Create(); CkHttpRequestW_AddParam(req,L"grant_type",L"password"); CkHttpRequestW_AddParam(req,L"scope",L"api/ratings api/addin rest"); CkHttpRequestW_AddParam(req,L"username",L"my_username"); CkHttpRequestW_AddParam(req,L"password",L"my_password"); // I have no idea of where to get the client_id or client_secret. // When you create a Moody's App, it only provides an "API Key". CkHttpRequestW_AddParam(req,L"client_id",L"my_client_id"); CkHttpRequestW_AddParam(req,L"client_secret",L"my_client_secret"); resp = CkHttpW_PostUrlEncoded(http,L"https://api.moodys.com/OAuth/Token",req); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); return; } wprintf(L"status code = %d\n",CkHttpResponseW_getStatusCode(resp)); responseBody = CkHttpResponseW_bodyStr(resp); wprintf(L"%s\n",responseBody); // Save the JSON to a file for future requests. if (CkHttpResponseW_getStatusCode(resp) == 200) { fac = CkFileAccessW_Create(); CkFileAccessW_WriteEntireTextFile(fac,L"qa_data/tokens/moodys.json",CkHttpResponseW_bodyStr(resp),L"utf-8",FALSE); } CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkFileAccessW_Dispose(fac); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.