PHP code example of apifreaks / sdk
1. Go to this page and download the library: Download apifreaks/sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
apifreaks / sdk example snippets
pifreaks\ApifreaksClient;
use Apifreaks\Requests\GeolocationLookupRequest;
use Apifreaks\Exceptions\ApifreaksApiException;
use Apifreaks\Exceptions\ApifreaksException;
$client = new ApifreaksClient();
try {
$response = $client->geolocationLookup(new GeolocationLookupRequest([
'apiKey' => 'your_api_key',
'ip' => '8.8.8.8',
]));
echo $response;
} catch (ApifreaksApiException $e) {
echo 'API error: ' . $e->getCode() . PHP_EOL;
print_r($e->getBody());
} catch (ApifreaksException $e) {
echo 'SDK error: ' . $e->getMessage() . PHP_EOL;
}
use Apifreaks\ApifreaksClient;
use Apifreaks\Environments;
$client = new ApifreaksClient([
'baseUrl' => Environments::Default_->value,
]);
use Apifreaks\Exceptions\ApifreaksApiException;
use Apifreaks\Exceptions\ApifreaksException;
try {
$response = $client->geolocationLookup($request);
} catch (ApifreaksApiException $e) {
echo 'Status code: ' . $e->getCode() . PHP_EOL;
print_r($e->getBody());
} catch (ApifreaksException $e) {
echo $e->getMessage() . PHP_EOL;
}
use Apifreaks\Requests\GeolocationLookupRequest;
$request = new GeolocationLookupRequest([
'apiKey' => 'your_api_key',
'ip' => '8.8.8.8',
]);
$client = new ApifreaksClient([
'maxRetries' => 3,
]);
$response = $client->geolocationLookup($request, [
'maxRetries' => 3,
]);
$client = new ApifreaksClient([
'timeout' => 30,
]);
$response = $client->geolocationLookup($request, [
'timeout' => 30,
]);
$client = new ApifreaksClient([
'headers' => [
'X-Custom-Header' => 'custom-value',
],
]);
$response = $client->geolocationLookup($request, [
'headers' => [
'X-Request-Header' => 'request-value',
],
]);
$response = $client->geolocationLookup($request, [
'queryParameters' => [
'filter' => 'active',
'sort' => 'desc',
],
]);