-274- v2.9
MySignals API's
9.1.2. PHP example
There is an example that you can download from:
http://downloads.libelium.com/mysignals/mysignals_web/api_cloud_v1.zip
1.- Extract the zip with the example
2.- Download the 'httpfull' library and place it in the /includes directory
http://phphttpclient.com/downloads/httpful.phar
3.- Edit the le example.php and ll $email and $password with your values
4.- Go to your web browser and load the example.php page
This will log you in the system, get a list of your members and get the latest 5 temperature values of one of your
users.
/*
*
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* By using it you accept the MySignals Terms and Conditions.
* You can nd them at: http://libelium.com/legal
*
*
* Version: 0.1
* Design: David Gascon
*/
include('includes/httpful.phar');
// Cong
$email = 'your@email.com';
$password = 'your_password';
// API Vars
$api_base = 'https://api.libelium.com/mysignals';
$api_headers = ['Accept' => 'application/x.webapi.v1+json'];
//1.- Login
$parameters = json_encode([
'email' => $email,
'password' => $password
]);
$response_login = \Httpful\Request::post($api_base . '/auth/login')
->sendsJson()
->body($parameters)
->addHeaders($api_headers)
->send();
echo "1.- Login: <br><br>".$response_login->raw_body."<hr><br>";
//Save the Token in the header array.
if($response_login->code == 200){
$api_headers['Authorization'] = 'Bearer '.$response_login->body->token;
}