我试图在 Drupal 中从外部 API 以 json 格式获取响应。我正在使用 HTTP 客户端管理器 Drupal 模块。 现在我只能在数组中获得 stdClass 对象格式的响应,并且所有响应键值都丢失。
我的原始代码:
public function findPosts() {
$client = $this->getClient();
$params = array('client_Id' => "12345",
"client_Secret" => "42452454",
"scope" => "read");
$response = $client->FindPosts($params);
dpm($response);
return ['#markup' => $response];
}
输出以下代码。我也需要它看起来像 [access_token] => eyJhbGciOiJIUzUxMiIsIn,[type] => bearer 等。
stdClass Object
(
[__CLASS__] => GuzzleHttp\Command\Result
[data:protected] => Array
(
[0] => eyJhbGciOiJIUzUxMiIsIn
[1] => bearer
[2] => 3600
[3] => 2022-11-09T10:48:47+00:00
[4] => read
[5] => MwA1ADkAZAA0AGIAZAA4AC0AOQAzADcA
[6] => 86400
[7] => 2022-11-10T09:48:47+00:00
)
)
当我尝试 $response->getBody() 或 $response->getContent() 或任何其他响应方法时,它会返回以下错误。
Error: Call to undefined method GuzzleHttp\Command\Result::getBody() in Drupal\http_client_manager_example\Controller\ExampleController->findPosts() (line 92 of modules/contrib/http_client_manager/modules/http_client_manager_example/src/Controller/ExampleController.php).
Drupal\http_client_manager_example\Controller\ExampleController->findPosts()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19) Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号