(Swift 3,4,5...) Magento Request with OAuth1.0a Authentication
Demonstrates sending a Magento request with OAuth1.0a authentication. (Using the Magento 1.x REST API)
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var success: Bool
let http = CkoHttp()!
http.oAuth1 = true
http.oAuthVerifier = ""
http.oAuthConsumerKey = "MAGENTO_CONSUMER_KEY"
http.oAuthConsumerSecret = "MAGENTO_CONSUMER_SECRET"
http.oAuthToken = "MAGENTO__TOKEN"
http.oAuthTokenSecret = "MAGENTO_TOKEN_SECRET"
http.accept = "application/json"
var url: String? = "http://www.inart.com/api/rest/products/store/2?limit=20&page=1"
var jsonStr: String? = http.quickGetStr(url)
if http.lastMethodSuccess != true {
print("\(http.lastErrorText!)")
return
}
print("Response status code = \(http.lastStatus.intValue)")
let json = CkoJsonObject()!
json.load(jsonStr)
json.emitCompact = false
print("\(json.emit()!)")
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
}
|