2

I'm trying to understand how Stream works, but I just don't get it... I have two feeds I want to create, they should be seperate from each other.

With the example below I thought that I'm first adding activities as Eric, I have one activity that goes just to Eric's feed, one that goes to the cpaentries feed and one that goes to the productcafe feed.

const ericToken = client.feed('timeline', 'eric').token
var ericFeed = client.feed('timeline', 'eric', ericToken);

// Add the activity to the feed
ericFeed.addActivity({
    actor: 'eric',
    tweet: 'Hello world',
    verb: 'tweet',
    object: 1
});


ericFeed.addActivity({
    actor: 'eric',
    tweet: 'Hello world, CPA EntriesNew',
    verb: 'tweet',
    object: 1,
    to: ['timeline:cpaentries']
});

ericFeed.addActivity({
    actor: 'eric',
    tweet: 'Hello world, Product CafeNew',
    verb: 'tweet',
    object: 1,
    to: ['timeline:productcafe']
});

Now I am trying to ONLY retrieve the timeline containing cpaentries activities. Think of this as the main feed every user should see when they open the app. I'm just generally confused about client.feed, the to field and following as well I suppose.

const cpaToken = client.feed('timeline', 'cpaentries').token
var cpaFeed = client.feed('timeline', 'cpaentries', cpaToken);


cpaFeed.get({limit:5}).then(function(body) {
    console.log(body);
    /* on success */
    }).catch(function(reason) {
    console.log(reason);
    /* on failure, reason.error contains an explanation */
});

This snippet basically just shows all posts, not only the cpaentries posts as I was hoping it would do.

Here's the body of my result:

{ results:
   [ { actor: 'eric',
       foreign_id: '',
       id: 'd2435d01-21bb-11e8-81f8-128899f22c76',
       object: '1',
       origin: null,
       target: '',
       time: '2018-03-07T03:58:40.503118',
       tweet: 'Hello world, CPA EntriesNew',
       verb: 'tweet' },
     { actor: 'eric',
       foreign_id: '',
       id: '83eb9b0e-21bb-11e8-a2ca-0a51ae8e7f7a',
       object: '1',
       origin: null,
       target: '',
       time: '2018-03-07T03:56:29.065704',
       tweet: 'Hello world, CPA EntriesNew',
       verb: 'tweet' },
     { actor: 'eric',
       foreign_id: '',
       id: 'fc9b804e-2154-11e8-b02a-128899f22c76',
       object: '1',
       origin: null,
       target: '',
       time: '2018-03-06T15:42:33.381897',
       tweet: 'Hello halli hallo world, CPA Entries',
       verb: 'tweet' },
     { actor: 'eric',
       foreign_id: '',
       id: '3602f521-2152-11e8-853b-0a51ae8e7f7a',
       object: '1',
       origin: null,
       target: '',
       time: '2018-03-06T15:22:41.199850',
       tweet: 'Hello world, CPA EntriesNew',
       verb: 'tweet' },
     { actor: 'eric',
       foreign_id: '',
       id: '281b133f-2152-11e8-8533-0a51ae8e7f7a',
       object: '1',
       origin: null,
       target: '',
       time: '2018-03-06T15:22:17.869808',
       tweet: 'Hello world, CPA EntriesNew',
       verb: 'tweet' } ],
}
2
  • can you include the content of body from the cpaFeed.get call to the question? Mar 6, 2018 at 16:23
  • two followup questions - is this code running in the browser or server-side? (If it's running server-side, you don't need the ericToken variable - client.feed('timeline', 'eric') will work just fine. is the timeline:eric feed "following" the timeline:cpaentries feed or the timeline:productcafe feed?
    – Ken Hoff
    Mar 8, 2018 at 17:03

1 Answer 1

0

With the example below I thought that I'm first adding activities as Eric, I have one activity that goes just to Eric's feed, one that goes to the cpaentries feed and one that goes to the productcafe feed.

That's almost correct. In your example, all activities will go into Eric's feed. The second activity will go into Eric's feed, and be copied to the cpaentries feed. The third activity will go into Eric's feed, and be copied to the productcafe feed.

You can think of the to param as a collection of feeds to which the activity will be copied.

To get the behavior you thought would happen, the second and third activities would be added directly to the cpaentries and productcafe feeds respectively, with no to param. E.g.:

const cpaentriesFeed = client.feed('timeline', 'cpaentries', cpaentriesToken);

cpaentriesFeed.addActivity({
    actor: 'eric',
    tweet: 'Hello world, CPA EntriesNew',
    verb: 'tweet',
    object: 1
});

const productcafeFeed = client.feed('timeline', 'productcafe', productcafeToken);

productcafeFeed.addActivity({
    actor: 'eric',
    tweet: 'Hello world, Product CafeNew',
    verb: 'tweet',
    object: 1
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.