get-stream 教程中缺少代码

Missing code in get-stream tutorial

更新了使用js实时监听的代码,但仍然没有任何反应。

我正在努力实现以下目标:

1) 'Eric' 在文件 eric.php:

中发送包含以下代码的提要
   <?php
      require_once 'PATH/TO/MY/vendor/autoload.php';

      $client = new GetStream\Stream\Client('mykey', 'mysecret');

      // For the feed group 'user' and user id 'eric' get the feed
      $ericFeed = $client->feed('user', 'eric');

      // Add the activity to the feed
      $data = [
        "actor"=>"eric",
        "verb"=>"like",
        "object"=>"3",
        "tweet"=>"Hello world"
      ];
      $ericFeed->addActivity($data);
    ?>

或者,我可以改用 JS,但这也不能解决问题:

     <script>
     // Initialize the client with your api key, no secret and your app id
     var client = stream.connect('key', null, 'id');
     // For the feed group 'user' and user id 'eric' get the feed
     // The access token at the end is only needed for client side integrations
     var ericFeed = client.feed('user', 'eric', 'key');
     // Add the activity to the feed
     ericFeed.addActivity({
     actor: 'eric', 
     tweet: 'Hello world', 
     verb: 'tweet', 
     object: 1
   });
  </script>

2) 登录到她的页面 jessica.php 的 Jessica 希望收到有关 Eri 提要的通知。按照教程,这就是我用来实现此目的的方法:

 <?php
   //load Pusher or stream libraries
   require_once '../../../vendor/autoload.php';

   $client = new GetStream\Stream\Client('mykey','mysecret');

   $client = new GetStream\Stream\Client('b5qhgudtn6my', '4qkfwmsvfrprm3zp5smuxfnvrcb227f8sf49pt7mene3ra8kmz2mgk3tkne4nync');
            // For the feed group 'user' and user id 'eric' get the feed


        //Stream
        $jessicaFlatFeed = $client->feed('timeline', 'jessica');
        $jessicaFlatFeed->followFeed('user', 'eric');
        $response = $jessicaFlatFeed->getActivities(0, 3);

        $ericFeed = $client->feed('user', 'eric');
        $token = $ericFeed->getToken();
 ?>
 <div class="12u 12u align-center">
   <h3>RECEIVE UPDATE HERE</h3>

   <script type="text/javascript" src="/stream-js-master/bower_components/getstream/dist/js/getstream.js"></script>
    <script type="text/javascript">
        var client = stream.connect('b5qhgudtn6my', null, '19328');
                // Javascript client side feed initialization
        var ericFeed = client.feed("user", "eric", "<?php echo $token;?>");

        // Listen to feed changes in realtime
        var promise = ericFeed.subscribe(function(data){
            alert("WORKING!");
            console.log("Working!!!", data);
        });
        // Add an activity when the websocket is ready
        promise.then(function() {
        ericFeed.addActivity({actor:"eric", verb: "tweet", object: 2, tweet: "AWESOME!"});
        });
      </script>
   </script>
 </div>

此时我希望在 Jessica 的页面中弹出警报消息,但它没有。

下面我报告教程中的代码

 https://getstream.io/get_started/?language=php

步骤 2/5 php:平面进纸:

    // See https://github.com/tbarbugli/stream-php for install instructions
// Initialize the client with your api key and secret
$client = new GetStream\Stream\Client('key', 'secret');
// For the feed group 'user' and user id 'eric' get the feed
$ericFeed = $client->feed('user', 'eric');
// Add the activity to the feed
$data = [
    "actor"=>"eric",
    "verb"=>"like",
    "object"=>"3",
    "tweet"=>"Hello world"
];
$ericFeed->addActivity($data);

注意:此代码是我在自己的代码 eric.php 中放入的代码。

3/5:php:关注

// Let Jessica's flat feed follow Eric's feed
$jessicaFlatFeed = $client->feed('timeline', 'jessica');
$jessicaFlatFeed->followFeed('user', 'eric');

注意:这是我在调用 JS 代码之前放在 jessica.php 顶部的内容。

5/5:php:实时(4/5 是我现在不需要的聚合提要)

// Listening to realtime updates is only available in JS
// You can pass the feed token as follows
// Generating tokens for client side usage
$token = **$user1**->getToken();
// Javascript client side feed initialization
// ericFeed = client.feed('user:eric', '{{ token }}');

注意:我用 $eric 替换了 $user1。 这部分代码放在eric.php里面,但是不清楚我需要用

做什么
   ericFeed = client.feed('user:eric', '{{ token }}');

在教程的步骤 5/5/ 中被注释掉了。

此时教程中没有给出更多代码。

已解决:我报告了 eric.phpjessica.php[ 的工作代码=23=]

eric.php(创建提要的人)

<?php
 //Stream: create feed
 require_once '../../../vendor/autoload.php';
 $client = new GetStream\Stream\Client('MY_KEY', 'MY_SECRET');

 // For the feed group 'user' and user id 'eric' get the feed
 $ericFeed = $client->feed('user', 'eric');

 // Add the activity to the feed
 $data = [
   "actor"=>"eric",
   "verb"=>"like",
   "object"=>"3",
   "tweet"=>"Hello world"
 ];
 $ericFeed->addActivity($data);
 //End stream: create feed
?>

jessica.php:(收到提要的人)

 <?php
   require_once '../../../vendor/autoload.php';
   $client = new GetStream\Stream\Client('MY_KEY', 'MY_SECRET');

   //Stream
   $ericFeed = $client->feed('user', 'eric');
   $token = $ericFeed->getToken();
   //Get stream 
 ?>


    <script type="text/javascript" src="path/to/getstream.js"></script> 
    <script type="text/javascript"> 

        var client = stream.connect('MY_KEY', null, 'APP_ID'); 
        var ericFeed = client.feed("user", "eric", "<?php echo $token?>"); 

        function callback(data) { 
        alert("New Feed Received!"); 
        console.log("New Feed received!!!", data); 
        } 

        function successCallback(data) { 
        console.log('now listening to changes in realtime'); 
        } 

        function failCallback(data) { 
        alert('something went wrong, check the console logs'); 
        console.log(data); 
        } 

        ericFeed.subscribe(callback).then(successCallback, failCallback); 
    </script>