连接到 getstream 时出错 php

Error connecting to getstream php

我正在按照 https://getstream.io/get_started/?language=php 中的示例来了解 getstream io 的工作原理。我 运行 遇到了一个让我感到困惑的错误。

 require_once './vendor/autoload.php';
 $client = new GetStream\Stream\Client('YOUR_API_KEY',     'API_KEY_SECRET');
$chris = $client->feed('user', 'chris');
 // I replaced Your api key and api key secret with the one         in my dashboard
// Add an activity; message is a custom field - tip: add unlimited         custom fields!
$data = array(
"actor" => "chris",
"verb" => "add",
"object" => "picture:10",
"foreign_id" => "picture:10",
"message" => "Beautiful bird. Absolutely beautiful. Phenomenal bird."
);

$chris->addActivity($data);


// jack's 'timeline' feed follows chris' 'user' feed:
$jack = $client->feed('timeline', 'jack');
$jack->followFeed('user', 'chris');


// Read the 'timeline' feed for jack, chris' post will now show up: 
$activities = $jack->getActivities(10);
var_dump($activities);

在我的 composer.json 文件中我这样做了

       "require": {
        "get-stream/stream": "2.2.8"
        }

我在 windows 上的本地主机上尝试了上面的代码,但出现了这个错误

Fatal error: Uncaught exception 'GuzzleHttp\ExceptionConnectException'     with message 'cURL error 28: Operation timed out after 0 milliseconds with 0 out of 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\xampp\htdocs\CorpersMate\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 186
 GuzzleHttp\Exception\ConnectException: cURL error 28: Operation timed out after 0 milliseconds with 0 out of 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in C:\xampp\htdocs\CorpersMate\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 186

大家有什么想法吗?

你应该提供指南 - 我们必须先注册才能获得它,这是不可能的。

将第二行改为

$client = new GetStream\Stream\Client(KEY, SECRET);

我将深入探讨为什么这对 Xampp 对您不起作用。能否将您的 cURL 选项、库版本等发送给我们?

同时,根据您构建的工作流程:

  1. 为 Chris 创建 Feed
  2. 构建一个 activity 并将其放在 Chris 的 feed 上
  3. 为 Jack 创建 Feed
  4. 杰克关注克里斯的动态
  5. 阅读 Jack 的提要并期待看到 Chris 的 activity

...当关注 Chris 的提要时,Jack 需要指定要复制的活动数量,否则 Jack 将只能看到从那时起的更新;杰克永远不会看到克里斯的 "picture:10"。您可以通过 followFeed() 发送第三个可选参数,指定在您开始关注时要复制到 Jack 的提要的项目数:

$jack->followFeed('user', 'chris', 100);

或者您可以将第 4 步移到第 1 步和第 2 步之间。如果 Jack 在 Chris 添加照片之前关注了 Chris,则该照片应该会显示在 Jack 的动态中。

后来我找到了解决问题的办法。问题在于试图验证我的证书的 guzzle 库。因为我需要一种方法在移动到生产服务器之前在本地服务器上对其进行测试,所以我不得不修改 guzzle 库中的客户端构造函数,这为我解决了问题。

 // file name is Client.php 

  public function __construct(array $config = ['verify' => false]) {
    if (!isset($config['handler'])) {
        $config['handler'] = HandlerStack::create();
    }

    // Convert the base_uri to a UriInterface
    if (isset($config['base_uri'])) {
        $config['base_uri'] = Psr7\uri_for($config['base_uri']);
    }

    $this->configureDefaults($config);
}