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
(C) Update an Inventory Listing using OAuth1 AuthenticationSee more Etsy ExamplesUpdates an inventory listing. This example uses OAuth1 authentication instead of providing an api_key=MY_ETSY_KEYSTRING query parameter.
#include <C_CkRest.h> #include <C_CkJsonObject.h> #include <C_CkOAuth1.h> void ChilkatSample(void) { HCkRest rest; BOOL success; HCkJsonObject json; HCkOAuth1 oauth1; BOOL autoReconnect; BOOL tls; const char *jsonText; const char *jsonResponseText; HCkJsonObject jsonResponse; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest = CkRest_Create(); // See this example for getting an OAuth1 token for Etsy json = CkJsonObject_Create(); success = CkJsonObject_LoadFile(json,"qa_data/tokens/etsy.json"); if (success == FALSE) { printf("Failed to load previously fetched Etsy OAuth1 access token.\n"); CkRest_Dispose(rest); CkJsonObject_Dispose(json); return; } oauth1 = CkOAuth1_Create(); CkOAuth1_putConsumerKey(oauth1,"app_keystring"); CkOAuth1_putConsumerSecret(oauth1,"app_shared_secret"); CkOAuth1_putToken(oauth1,CkJsonObject_stringOf(json,"oauth_token")); CkOAuth1_putTokenSecret(oauth1,CkJsonObject_stringOf(json,"oauth_token_secret")); CkOAuth1_putSignatureMethod(oauth1,"HMAC-SHA1"); CkOAuth1_GenNonce(oauth1,16); autoReconnect = TRUE; tls = TRUE; success = CkRest_Connect(rest,"openapi.etsy.com",443,tls,autoReconnect); if (success == FALSE) { printf("%s\n",CkRest_lastErrorText(rest)); CkRest_Dispose(rest); CkJsonObject_Dispose(json); CkOAuth1_Dispose(oauth1); return; } // Tell the REST object to use the OAuth1 object. success = CkRest_SetAuthOAuth1(rest,oauth1,TRUE); jsonText = "[{\"product_id\":1999949999,\"property_values\":[],\"offerings\":[{\"offering_id\":9999905883,\"price\":\"36.23\",\"quantity\":1}]}]"; CkRest_AddQueryParam(rest,"products",jsonText); CkRest_AddHeader(rest,"Content-Type","application/x-www-form-urlencoded"); jsonResponseText = CkRest_fullRequestFormUrlEncoded(rest,"PUT","/v2/listings/228827035/inventory"); if (CkRest_getLastMethodSuccess(rest) == FALSE) { printf("%s\n",CkRest_lastErrorText(rest)); CkRest_Dispose(rest); CkJsonObject_Dispose(json); CkOAuth1_Dispose(oauth1); return; } jsonResponse = CkJsonObject_Create(); CkJsonObject_Load(jsonResponse,jsonResponseText); CkJsonObject_putEmitCompact(jsonResponse,FALSE); printf("%s\n",CkJsonObject_emit(jsonResponse)); printf("Response status code: %d\n",CkRest_getResponseStatusCode(rest)); CkRest_Dispose(rest); CkJsonObject_Dispose(json); CkOAuth1_Dispose(oauth1); CkJsonObject_Dispose(jsonResponse); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.