簡體   English   中英

傳遞給 GuzzleHttp\\Client::request() 的參數 3 必須是數組類型,給定字符串

[英]Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given

我正在試驗 SammyK/LaravelFacebookSdk。 嘗試從示例中運行此行: $response = Facebook::get('/me?fields=id,name,email', 'user-access-token');

依次運行/var/www/vendor/facebook/php-sdk-v4/src/Facebook/HttpClients/FacebookGuzzleHttpClient.php line 61

public function send($url, $method, $body, array $headers, $timeOut)
{
    $options = [
        'headers' => $headers,
        'body' => $body,
        'timeout' => $timeOut,
        'connect_timeout' => 10,
        'verify' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem',
    ];
    $request = $this->guzzleClient->createRequest($method, $url, $options);

    try {
        $rawResponse = $this->guzzleClient->send($request);
    } catch (RequestException $e) {
        $rawResponse = $e->getResponse();

        if ($e->getPrevious() instanceof RingException || !$rawResponse instanceof ResponseInterface) {
            throw new FacebookSDKException($e->getMessage(), $e->getCode());
        }
    }

    $rawHeaders = $this->getHeadersAsString($rawResponse);
    $rawBody = $rawResponse->getBody();
    $httpStatusCode = $rawResponse->getStatusCode();

    return new GraphRawResponse($rawHeaders, $rawBody, $httpStatusCode);
}

調用/var/www/vendor/guzzlehttp/guzzle/src/Client.php line 87

public function __call($method, $args)
{
    if (count($args) < 1) {
        throw new \InvalidArgumentException('Magic request methods require a URI and optional options array');
    }

    $uri = $args[0];
    $opts = isset($args[1]) ? $args[1] : [];

    return substr($method, -5) === 'Async'
        ? $this->requestAsync(substr($method, 0, -5), $uri, $opts)
        : $this->request($method, $uri, $opts);
}

此方法將輸入解釋為array('method' => 'createRequest', 'uri' => 'GET'))

更改索引似乎可以糾正錯誤(盡管會出現其他問題)

 $uri = $args[1];
 $opts = isset($args[2]) ? $args[2] : [];

但是因為編輯其他包是一個非常糟糕的做法,我應該如何糾正這個錯誤?

我遇到了同樣的問題。 更改索引對我不起作用,但我找到了一種解決方法。 安裝php-curl擴展通過cURL切換整個工作流程,因此問題就消失了。

由於Facebook SDK 5.x使用guzzle版本5.因此降級guzzle庫將解決方法

$ composer require guzzlehttp/guzzle:~5.0

使用

new \GuzzleHttp\Psr7\Request($method, $url, $headers, ..)

代替

$this->guzzleClient->createRequest

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM