Yurii Kosiak
Yurii Kosiak

Reputation: 410

Unknown category error

When I use the category property I see this error:

Fatal error: Uncaught CloudRail\Error\IllegalArgumentError: Illegal argument used: Unknown category. in ...\vendor\cloudrail\library-php\src\Service\GooglePlaces.php

Without category all work fine. My code:

$cr_service = load_cloudrail_service('GooglePlaces');
$retrievedPOIs = $cr_service->getNearbyPOIs(50.45594, 30.465612, 40000, '', ['restaurant']);

function load_cloudrail_service($serviceName = 'Foursquare') {
  global $options;

  Settings::$licenseKey = $options['cr_key'];

  switch ($serviceName) {
    case 'Foursquare':
    $result = new Foursquare( $options['fsquare_id'], $options['fsquare_secret'] );
    break;
    case 'Yelp':
    $result = new \CloudRail\Service\Yelp( $options['yelp_key'] );
    break;
    case 'GooglePlaces':
    $result = new GooglePlaces( $options['gplaces_key'] );
    break;
  }
  return $result;
}

The same error with other services. What wrong? Thank you.

Upvotes: 1

Views: 273

Answers (2)

Yurii Kosiak
Yurii Kosiak

Reputation: 410

Thank you for update to 1.0.2 version. It helped. But when I had tried to update version I have received incorrect version of cloudrail. To avoid this issue just remove composer.lock or use command composer install update to update dependencies in lock file.

Upvotes: 0

Felipe Cesar Assis
Felipe Cesar Assis

Reputation: 398

I dont know if you posted the whole class code, but it seems that the import is not being done properly. To avoid the unknown category error be sure that you loaded the proper classes:

If integrated through composer you can load all classes using the default autoloader, and you just need to specify what categories are you using with the require (or require_once) statement and make sure that you have installed the SDK using composer install or equivalent. Test the following code (I have already tested for CloudRail v1.0.1), if it is not working properly, then it should be something either on the autoload or the composer:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use CloudRail\Service\Foursquare;
use CloudRail\Service\GooglePlaces;
use CloudRail\Service\Yelp;

use CloudRail\Settings;

Settings::$licenseKey = "[CLOUDRAIL_KEY]";

/**
 * @var \CloudRail\Interfaces\PointsOfInterest
 */
$service = null;

/**
 * @var string
 */
$serviceName = "GooglePlaces"; //TODO:Just change the interface name :)

switch ($serviceName){
    case "Foursquare":
        $service = new Foursquare( "[FOURSQUARE_KEY]","[FOURSQUARE_SECRET]]");
        break;
    case "Yelp":
        $service = new Yelp( "[API_KEY]");
        break;
    case "GooglePlaces":
        $service = new GooglePlaces( "[API_KEY]");
        break;
}

$retrievedPOIs = $service->getNearbyPOIs( -15.7662,-47.8829,3000,"cafe",[]);

var_dump($retrievedPOIs);

Upvotes: 0

Related Questions