连接到getstream php时出错

时间:2016-09-23 23:55:14

标签: php curl getstream-io

我正在关注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上的localhost机器上尝试了上面的代码,但是出现了这个错误

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

任何想法的人?

3 个答案:

答案 0 :(得分:1)

你应该提供指导 - 我们必须首先注册才能获得它,它不会发生。

将第二行更改为

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

答案 1 :(得分:1)

我后来发现了对这个问题的调整。问题出在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);
}

答案 2 :(得分:0)

我将深入研究为什么这对Xampp无效。您能将您的cURL选项,库版本等发送给我们吗?

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

  1. 为Chris建立一个Feed
  2. 建立活动并将其放在Chris'feed
  3. 为Jack建立一个Feed
  4. 杰克跟随克里斯的饲料
  5. 阅读杰克的饲料,希望看到克里斯的活动
  6. ...杰克需要指定一些活动,以便在关注Chris的时候复制,否则杰克只会看到从那一点开始的更新;杰克永远不会看到克里斯的“图片:10”。您可以通过followFeed()发送第三个可选参数,该参数指定当您开始关注时要复制到Jack的Feed的项目数:

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

    或者你可以在步骤1和2之间移动第4步。如果杰克在克里斯添加照片之前跟随克里斯,那么它应该出现在杰克的饲料上。

相关问题