Code Examples
The code samples of sending requests to justLikeAPI in PHP, Java, Python, and cURL can be found below. In all the cases, the result is a JSON code that can be used for further analysis, writing data into an Excel file, and much more.
Python examples
import requests
import json
auth_token='c7324ddf-657c-4078-8c03-fdec1890a19f'
header = {'Authorization': 'Bearer ' + auth_token}
data = {
'propertyUrl': 'https://www.google.com/search?q=hilton+prague+old+town',
'reviewLimit': 50
}
url = 'https://api.justlikeapi.io/reviews/get'
response = requests.post(url, json=data, headers=header)
print(response)
print(json.dumps(response.json()))
PHP examples
// PROVIDE YOUR API KEY
$apiKey = "your api key";
// SPECIFY REQUEST TYPE, IT CAN BE "get", "verify", "ads" (facebook only) or "recommendations" (facebook only)
$requestType = "get";
// ENTER THE ADDRESS OF THE PROPERTY YOU WANT TO CHECK
$propertyUrl = "your property url";
// AND ADDITIONAL SEARCH PARAMETERS, OR LEAVE THEM BLANK
$dateFrom = "2022-01-16";
$reviewLimit = "100";
$url = 'https://api.justlikeapi.io/reviews/' . $requestType;
$data = "{\"propertyUrl\":\"{$propertyUrl}\"," .
"\"dateFrom\": \"{$dateFrom}\"," .
"\"reviewLimit\":\"{$reviewLimit}\"}";
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "content-type: application/json\r\n".
"Authorization: Bearer {$apiKey}\r\n",
'method' => 'POST',
'content' => $data,
'ignore_errors' => true
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
// HANDLE ERROR;
}
// DO SOMETHING WITH $result
var_dump($result);
Java examples
import java.io.IOException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class jlaRequest {
public static void main (String[] args) {
// PROVIDE YOUR API KEY
String apiKey = "your api key";
// SPECIFY REQUEST TYPE, IT CAN BE "get", "verify", "ads" (facebook only) or "recommendations" (facebook only)
String requestType = "get";
// ENTER THE ADDRESS OF THE PROPERTY YOU WANT TO CHECK
String propertyUrl = "your property url";
// AND ADDITIONAL SEARCH PARAMETERS, OR LEAVE THEM BLANK
String dateFrom = "2022-01-16";
String reviewLimit = "100";
JsonNode responseJson = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost("https://api.justlikeapi.io/reviews/" + requestType);
postRequest.addHeader("content-type", "application/json");
postRequest.addHeader("Authorization", "Bearer " + apiKey);
StringEntity requestBody = new StringEntity("{"
+ "\"propertyUrl\":\""+ propertyUrl +"\","
+ "\"dateFrom\": \""+ dateFrom +"\","
+ "\"reviewLimit\":\""+ reviewLimit +"\""
+ "}", "UTF-8");
postRequest.setEntity(requestBody);
try {
CloseableHttpResponse httpResponse = httpClient.execute(postRequest);
String responseJSON = EntityUtils.toString(httpResponse.getEntity());
ObjectMapper objectMapper = new ObjectMapper();
try {
responseJson = objectMapper.readValue(responseJSON, JsonNode.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
} finally {
httpResponse.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
// DO SOMETHING WITH responseJson
}
}