问题
I am trying to perform CURL get request in guzzlehttp to check if a user exists in a CRM. Whenever I try to perform the request I get the following error in the title, I haven't been able to find any resources online for this specific problem. Any ideas would be super helpful, if you require any additional info please let me know in the comments.
Included packages:
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));
}
}
}
I have a post request function to gain an access token that works correctly.
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());
}
}
回答1:
The issue was caused due to guzzlehttp being directly supported in drupal-8, caused a confliction with the package installed via composer.
After removing composer libraries for guzzle and use the following documentation: https://www.drupal.org/docs/8/modules/http-client-manager/introduction
来源:https://stackoverflow.com/questions/60468861/call-to-undefined-function-guzzlehttp-psr7-get-message-body-summary