1

当我使用 category 属性时,我看到了这个错误:

致命错误:未捕获的 CloudRail\Error\IllegalArgumentError:使用了非法参数:未知类别。在 ...\vendor\cloudrail\library-php\src\Service\GooglePlaces.php

没有类别一切正常。我的代码:

$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;
}

与其他服务相同的错误。怎么了?谢谢你。

4

2 回答 2

0

我不知道您是否发布了整个课程代码,但似乎导入没有正确完成。为避免未知类别错误,请确保您加载了正确的类:

如果通过composer集成,您可以使用默认的自动加载器加载所有类,您只需要使用 require(或 require_once)语句指定您使用的类别,并确保您已使用composer install或等效安装 SDK。测试以下代码(我已经为 CloudRail v1.0.1 测试过),如果它不能正常工作,那么它应该是自动加载或作曲家上的东西:

<?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);
于 2018-06-04T23:27:00.593 回答
0

感谢您更新到 1.0.2 版本。它有帮助。但是当我尝试更新版本时,我收到了不正确的 cloudrail 版本。为避免此问题,只需删除composer.lock或使用命令composer install update更新锁定文件中的依赖项。

于 2018-08-01T03:39:41.333 回答