调用未定义函数GuzzleHttp \ Psr7 \ get_message_body_summary()

问题描述 投票:0回答:1

我正在尝试在guzzlehttp中执行CURL获取请求,以检查CRM中是否存在用户。每当我尝试执行请求时,标题中都会出现以下错误,但我无法在线找到有关此特定问题的任何资源。任何想法都将非常有帮助,如果您需要任何其他信息,请在评论中让我知道。

包含的软件包:

require(__DIR__ . "/../../vendor/autoload.php");
require_once(__DIR__ . "/../../helpers/Validation.php");
use Symfony\Component\Dotenv\Dotenv;
use GuzzleHttp\Client;
use GuzzleHttp\Request;
use GuzzleHttp\RequestOptions;
use GuzzleHttp\Psr7;
use GuzzleHttp\Stream\Stream;
use Drupal\Core\Site\Settings;

// Load our environment variables
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . "/../../.env");

private function checkDuplicate() {
  // If no errors we can submit the registrant
  // \Drupal::logger('signup')->notice("access token", print_r($this->_accessToken, TRUE));
  if(!$this->_errors) {
    $checkNewUser = new Client();
    try {
      $options = [
        'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Authorization' => "Bearer " . $this->_accessToken
      ],
      "query" => '$filter=email%20eq%20"' .$this->_email . '"&$fields=Contact Key,First Name,Last Name'
    ];
    $result = $checkNewUser->get($_ENV['REST_API_URL'], $options);
  } catch (RequestException $e) {
    \Drupal::logger('signup')->error("error " . print_r($e->getRequest(), TRUE));
    if ($e->hasResponse()) {
      \Drupal::logger('signup')->error("error " . print_r($e->getRequest(), TRUE));
      echo $e->getRequest() . "\n";
      \Drupal::logger('signup')->error("error " . print_r($e->getResponse(), TRUE));
    }
  }
}

我具有发布请求功能来获取正常工作的访问令牌。

private function getAccessToken() {
  try {
    $requestAccessToken = new Client();

    $options = [
      'headers' => [
        'Accept'     => 'application/json',
      ],
      "form_params" => [
        "grant_type" => "client_credentials", 
        "client_id" => $_ENV["CLIENT_ID"], 
        "client_secret" => $_ENV["CLIENT_SECRET"]
      ]
    ];
    $result = $requestAccessToken->post($_ENV['CLIENT_API_URL'], $options);

    return (string) $result->getBody();
  }
  catch(Exception $error) {
    \Drupal::logger('signup')->error("error " . $error-getMessage());
  }
}
php composer-php guzzle guzzlehttp
1个回答
0
投票

此问题是由于drupal-8直接支持guzzlehttp,与通过composer安装的软件包发生冲突。

删除作曲家的库后,使用以下文档:https://www.drupal.org/docs/8/modules/http-client-manager/introduction

© www.soinside.com 2019 - 2024. All rights reserved.