![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 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.Note: This example requires Chilkat v11.0.0 or greater.
#include <CkHttpW.h> #include <CkHttpRequestW.h> #include <CkHttpResponseW.h> #include <CkFileAccessW.h> void ChilkatSample(void) { bool success = false; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; CkHttpRequestW req; req.AddParam(L"grant_type",L"password"); req.AddParam(L"scope",L"api/ratings api/addin rest"); req.AddParam(L"username",L"my_username"); req.AddParam(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". req.AddParam(L"client_id",L"my_client_id"); req.AddParam(L"client_secret",L"my_client_secret"); req.put_HttpVerb(L"POST"); req.put_ContentType(L"application/x-www-form-urlencoded"); CkHttpResponseW resp; success = http.HttpReq(L"https://api.moodys.com/OAuth/Token",req,resp); if (success == false) { wprintf(L"%s\n",http.lastErrorText()); return; } wprintf(L"status code = %d\n",resp.get_StatusCode()); const wchar_t *responseBody = resp.bodyStr(); wprintf(L"%s\n",responseBody); // Save the JSON to a file for future requests. if (resp.get_StatusCode() == 200) { CkFileAccessW fac; fac.WriteEntireTextFile(L"qa_data/tokens/moodys.json",resp.bodyStr(),L"utf-8",false); } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.