我正在尝试从我的Delphi项目访问ClickBank API,以检查客户是否有有效的订阅。
我找到了API文档here,但没有Delphi示例。所以我试图创建我自己的小例子,但是我不能用Indy的TIdHTTP来解决它。
有没有人能指出我正确的方向,或许会设置一个最小的例子?
P.S:我试过看C#样本,但我不能把它移植到Delphi。
答案 0 :(得分:4)
ClickBank示例C#位于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();
PHP版本是 https://sandbox.clickbank.com/api_12_examples/api_example.php
你会发现他们在这里没有做太多设置......只需设置两个标题并执行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);
在Delphi中 - 一个快速演示是在表单上删除TIdHTTP1客户端,以及Button和Memo。然后点击按钮(其中xxx =您的开发人员密钥,yyy =您的api密钥)执行相同操作 - 设置两个标头并执行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');