开发者

Accessing Clickbank API through Delphi's TIdHTTP?

I am trying to access the ClickBank API from my Delphi project, to check if a customer has a valid subscription.

I found the API Documentation here, but there are no Delphi examples. So I am开发者_如何学运维 trying to create my own little example, however I just cant figure it out with Indy's TIdHTTP.

Could anyone point me in the right direction, perhaps set up a minimal example?

P.S: I tried looking at the C# sample, however I cant port it to Delphi.


ClickBank sample C# is found here https://sandbox.clickbank.com/api_12_examples/api_example.csharp

HttpWebRequest request = (HttpWebRequest)
    WebRequest.Create("https://api.clickbank.com/rest/1.2/orders/list");
request.Accept = "application/xml";
request.Headers.Add(HttpRequestHeader.Authorization,
        "<< DEVELOPER KEY >>:<< API KEY >>");
request.Method = "GET";

HttpWebResponse response = (HttpWebResponse) request.GetResponse();

The PHP version is https://sandbox.clickbank.com/api_12_examples/api_example.php

You'll see that they aren't doing much setup here... just setting two headers and performing a GET.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/orders/list");
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Accept: application/xml",
        "Authorization: << DEVELOPER KEY >>:<< API KEY >>"));
$result = curl_exec($ch);
curl_close($ch);

In Delphi - a quick demo is to drop a TIdHTTP1 client on a form, along with a Button and a Memo. Then on an onclick of the button (where xxx= your developer key and yyy= your api key) do the same - set two headers and perform a GET:

IdHTTP1.Request.Accept := 'application/xml';
IdHTTP1.Request.CustomHeaders.Add('Authorization: xxx:yyy');
Memo1.Text := IdHTTP1.Get('https://api.clickbank.com/rest/1.2/orders/list');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜