Php Request

95 views
Skip to first unread message

off...@lupo-solutions.com

unread,
Jan 13, 2012, 3:55:53 PM1/13/12
to gauge...@googlegroups.com
Hey,

I am beginning to love your thing...but... i want to try the API. Can you post an Example on how to connect to your API via Php?
I have seen CURL, but i'm not the best at using curl...;)

Thank you!

off...@lupo-solutions.com

unread,
Jan 13, 2012, 4:13:53 PM1/13/12
to gauge...@googlegroups.com
Nevermind...Got it myself:
For those who need it:
<? 
$headers = array("X-Gauges-Token: API_KEY");
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://secure.gaug.es/gauges'); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($ch); 
curl_close($ch); 

print $data;
?>

Emilio Silvas

unread,
Jan 23, 2012, 5:16:10 PM1/23/12
to gauge...@googlegroups.com
Do you happen to have an example of how you managed to put changes to the API? I am looking to create a series of PHP function to manage our account and I am working on updating information. Any help would be appreciated.

Emilio Silvas

unread,
Jan 24, 2012, 5:29:54 PM1/24/12
to gauge...@googlegroups.com
This is how I updated the changes via the API (along with some simple error checking). I am also working on a (small, but growing) PHP library for accessing the Gauges API. I will post a link to it later when I am done.

<?php
$main_account_token = "YOUR_API_TOKEN";

$new_info = array("first_name" => "Emilio");
$my_new_info = $this->set_gauges_info($main_account_token, $new_info);
echo "my_new_info<pre>"; var_dump($my_new_info); echo "</pre>";
if (is_numeric($my_new_info)) {
$error = $this->gauges_api_errors($my_new_info);
echo "ERROR: ".$error."<br />";
}

public function set_gauges_info($token="",$items=array()) {
//Only one item can be changed at a time
if (($token!="") && (count($items)==1)) {
$qry_str = "";
$values = count($items);
$count = 0;
foreach($items AS $a => $b) {
$qry_str .= $a.'='.$b;
$count++;
if ($count<$values) { $qry_str .= ","; }
}

$headers = array("X-Gauges-Token: ".$token);
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://secure.gaug.es/me'); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry_str);
$data = curl_exec($ch); 
curl_close($ch);
return json_decode($data);
}
return false;
}

public function gauges_api_errors($error=0) {
$result = "";
switch($error) {
case -1:
$result = "Token/API Client description is empty.";
break;
case -2:
$result = "1) Token/API Client description is empty, or 2) API client name error.";
break;
case -3:
$result = "API client name not present.";
break;
case -4:
$result = "API client key not present.";
break;
case -5:
$result = "Token/API Client key is empty.";
break;
default:
break;
}
return $result;
}
?>

Emilio Silvas

unread,
Feb 13, 2012, 8:54:44 PM2/13/12
to gauge...@googlegroups.com
Here is a link to the Github repo I created for my API calls. I'm not likely to work on it any longer as my employer has decided to use an in-house solution. But, this might help someone else solve their problem(s).

Reply all
Reply to author
Forward
0 new messages