|  | 
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 <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkFileAccessW.h> void ChilkatSample(void) { BOOL success; HCkHttpW http; HCkHttpRequestW req; HCkHttpResponseW resp; const wchar_t *responseBody; HCkFileAccessW fac; success = FALSE; // 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"); CkHttpRequestW_putHttpVerb(req,L"POST"); CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded"); resp = CkHttpResponseW_Create(); success = CkHttpW_HttpReq(http,L"https://api.moodys.com/OAuth/Token",req,resp); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkHttpResponseW_Dispose(resp); 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); } CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkHttpResponseW_Dispose(resp); CkFileAccessW_Dispose(fac); } | ||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.