clicky api connection using php curl failed -


i wants create url connecting "clicky api" "http://api.clicky.com/api/stats/4?site_id=32145&sitekey=94d117119dsfa&type=visitors" have developed curl code below,

$url = 'http://api.clicky.com/api/stats/4'; $info = array(             'site_id'=>'32145',         'sitekey'=>'94d117119dsfa',         'type'=>'visitors'     );     $post_field_string = http_build_query($info, ',', '&');     $ch = curl_init();     curl_setopt($ch, curlopt_url, $url);     curl_setopt($ch, curlopt_returntransfer, true);     curl_setopt($ch, curlopt_ssl_verifypeer, false);     curl_setopt($ch, curlopt_ssl_verifyhost, false);     curl_setopt($ch, curlopt_postfields, $post_field_string);     curl_setopt($ch,curlopt_post,1);     curl_setopt($ch, curlopt_header,1);     curl_setopt($ch, curlopt_verbose,1);     curl_setopt($ch, curlopt_httpheader, array(     'content-type: application/json',     'accept: application/json'));      curl_setopt($ch, curlopt_httpheader,array("expect:  "));     $exec = curl_exec($ch);     $header_size = curl_getinfo($ch, curlinfo_header_size);     $header = substr($response, 0, $header_size);     $body = substr($response, $header_size);     echo '<pre>';     print_r($exec); 

but output "resource id #2" , when check in inspect window response as,

<?xml version="1.0" encoding="utf-8"?> <response status="fail"> <error><![cdata[the 'type' parameter required.      specifies data type(s) want returned      api.]]></error> </response> 

so, can 1 tell me missed step. please me in solving this.

i made freelance client while ago. calls php script via js , puts graph "googlecharts"

explanation:

$_post have data needed form url, siteid , key statically placed in php file security , file_get_contents() gets data clicky

<?php // show errors comment when in production ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1);  //allow origin or can set domain name here header("access-control-allow-origin: *");  $input = $_post; //the data send used $input['site_id'] = "yoursiteid"; $input['sitekey'] = "yoursitekey"; unset($input['url']); $output = http_build_query($input); $url = $_post['url']."?".$output; $data = file_get_contents($url);  print_r($data); ?> 

this main.html file

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> </script>  <body>     <div id="linechart_material" style="width: 900px; height: 500px"></div>     <button onclick="change('/auction-list/');">change url</button>     <div id="map_div" style="width: 900px; height: 500px"></div> </body> <script type="text/javascript">     google.charts.load("current", {         packages: ["map", "line"]     }); </script> <script>      google.charts.setonloadcallback(new_req);     var url = "http://localhost/clicky.php";     var item = "/business-development/";      var frequency = "daily";     var date = "last-30-days";     var type = "pages";     function change(myitem){         item = myitem;         new_req();     }     function new_req() {         console.log(item);         var fdata = {             "url": "https://api.clicky.com/api/stats/4",             "type": type,             "date": date,             "output": "json",             "frequency": frequency,             "item": item,             "daily": "1"         };         ajax_request(url, fdata, format_chart_data);         var gdata = {             "url": "https://api.clicky.com/api/stats/4",             "type": "regions",             "date": date,             "output": "json"         };         ajax_request(url, gdata, format_graph_data);     }      function ajax_request(url, data, callback) {         $.ajax({             url: url,             type: 'post',             data: data,             timeout: 40000,             datatype: 'json',             success: callback,             error: function(xmlhttprequest, textstatus, errorthrown) {                 response = "err--" + xmlhttprequest.status + " -- " + xmlhttprequest.statustext;                 console.log(response);             }         });     }      function format_chart_data(result) {         console.log(result);         var graph_data = new google.visualization.datatable();         graph_data.addcolumn('string', 'date');         graph_data.addcolumn('number', 'visitors');         graph_data.addcolumn('number', 'blank');         var data = result[0].dates;         var = 0;         var j = data.length;         console.log(data.reverse());         (var in data) {             var date = data[i].date.split("-");             var year = date[0];             var month = date[1];             var day = date[2];              graph_data.addrow([(day + " / " + month + " / " + year), parseint(data[i].items[0].value), 0]);         }           var chart1_options = {             title: "stats",             vaxis: {                 title: "listing",                 titletextstyle: {                     color: 'red'                 }             }         };          var chart = new google.charts.line(document.getelementbyid('linechart_material'));         chart.draw(graph_data, chart1_options);       }      function format_graph_data(result) {         //console.log(json.stringify(result));         var map_data = new google.visualization.datatable();         map_data.addcolumn('string', 'regions');         map_data.addcolumn('string', 'name [percentage]');          var drt = result[0].dates[0].date.split(",");         var date_range = "from " + drt[0] + " " + drt[1];         console.log(date_range);         var data = result[0].dates[0].items;         (var in data) {             map_data.addrow([data[i].title, data[i].title+" ["+data[i].value_percent+"%]"]);          }         var chart2_options = {             showtip: true         };         var map = new google.visualization.map(document.getelementbyid('map_div'));         map.draw(map_data, chart2_options);          settimeout(function() {             //  new_req("default");         }, 40000);     } </script> 

Comments