dsvf46980 2015-10-01 15:30
浏览 71
已采纳

如何使用Kimono RESTful API更新参数?

Specifically I am looking to update the URLs that are to be scraped. Documentation can be found here: https://www.kimonolabs.com/apidocs#SetCrawlUrls

Unfortunately my knowledge about cURL and RESTful APIs is limited to say the least. My most recent failed attempt was:

$ch = curl_init("https://kimonolabs.com/kimonoapis/");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'kimonoapis/$api_id/update'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

where $data is an array of:

array(2) {
  ["apikey"]=>
  string(32) "API_KEY"
  ["urls"]=>
  array(2) {
    [0]=>
    string(34) "URL 1"
    [1]=>
    string(34) "URL 2"
  }
}

I have also tried variations of json_encode, passing the parameters in the query string, and different variations of cURL but have not be successful thus far. How do you successfully take advantage of their RESTful API?

  • 写回答

2条回答 默认 最新

  • doumeng06063991 2015-10-07 22:27
    关注
    $array = array('apikey' => 'API_KEY', 'urls' => array('URL_1', 'URL_2'));
    $postvars = http_build_query($array);
    $url = "https://kimonolabs.com/kimonoapis/{API_ID}/update";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
    $result = curl_exec($ch);
    curl_close($ch);
    

    After a lot more trail, error, and Google this is what I finally got to work. Thanks for all the help @JohnSvensson

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题