OK so im a noob when it comes to APi's. I have used wundergrounds api with out a problem. However im trying to use LogMeIn's REST API with php and i must be doing something wrong.
The instruction say to Check your Credentials
The first call should be GET /v1/authentication to check if your credentials are valid. So if your CompanyID is 1234567890 and your PSK is abcde12345ABCDE12345 (normally an actual PSK would be 128 characters long), the action can be called as:
$ curl https://secure.logmein.com/public-api/v1/authentication -i -H "Accept: application/JSON; charset=utf-8" -H "Authorization: {\"companyId\": 1234567890, \"psk\": \"abcde12345ABCDE12345\"}"
Where the -H argument sends a HTTP header and the -i argument shows the header of the response.
Response:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 16
Content-Type: application/JSON; charset=utf-8
Server: Microsoft-IIS/7.5
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"'
X-Powered-By: ASP.NET
Date: Mon, 11 Nov 2013 15:12:57 GMT
{"success":true}
so here is my PHP:
<?php
$json_string_LogMeIn = file_get_contents("https://secure.logmein.com/public-api/v1/authentication -i -H "Accept: application/JSON; charset=utf-8" -H "Authorization: {\"companyId\": 1234567890, \"psk\": \"abcde12345ABCDE12345\"}"");
$parsed_json_LogMeIn = json_decode($json_string_LogMeIn);
echo $parsed_json_LogMeIn;
?>
I added my company code in place of 1234567890 and my generated psk in place of abcde12345ABCDE12345
when i open the php page i get nothing
file_get_contents()
doesn't work like you're trying to, use cURL
instead, i.e.:
$headers = array(
"Accept: application/JSON; charset=utf-8",
"Authorization: {\"companyId\": 1234567890, \"psk\": \"abcde12345ABCDE12345\"}",
);
$url = "https://secure.logmein.com/public-api/v1/authentication";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
# {"success":false} / which is correct since I'm using a fake Authorization
Update:
It seems that you need to enable curl
on php.ini
, please refer to this link